1
2
3
4
5
6
7
8
9
10
11 package org.mule.util.store;
12
13 import org.mule.api.lifecycle.InitialisationException;
14 import org.mule.api.store.ObjectStoreException;
15 import org.mule.api.store.ObjectStoreNotAvaliableException;
16 import org.mule.tck.AbstractMuleTestCase;
17
18 import java.io.Serializable;
19
20 public class MonitoredObjectStoreTestCase extends AbstractMuleTestCase
21 {
22 private static final int EXPIRATION_INTERVAL = 500;
23
24 public void testShutdownWithHangingExpireThread() throws Exception
25 {
26 ExpiringStore store = createExpiringStore();
27
28
29 Thread.sleep(EXPIRATION_INTERVAL * 2);
30
31
32
33 store.dispose();
34
35 assertTrue(store.expireStarted);
36 assertFalse(store.expireFinished);
37 }
38
39 private ExpiringStore createExpiringStore() throws InitialisationException
40 {
41 ExpiringStore store = new ExpiringStore();
42 store.setExpirationInterval(EXPIRATION_INTERVAL);
43 store.initialise();
44
45 return store;
46 }
47
48 private static class ExpiringStore extends AbstractMonitoredObjectStore<String>
49 {
50 protected boolean expireStarted = false;
51 protected boolean expireFinished = false;
52
53 public ExpiringStore()
54 {
55 super();
56 }
57
58 @Override
59 protected void expire()
60 {
61 try
62 {
63 expireStarted = true;
64 Thread.sleep(EXPIRATION_INTERVAL * 10);
65 expireFinished = true;
66 }
67 catch (InterruptedException e)
68 {
69 throw new RuntimeException("expire was interrupted", e);
70 }
71 }
72
73 public boolean contains(Serializable id) throws ObjectStoreNotAvaliableException
74 {
75 return false;
76 }
77
78 public String remove(Serializable id) throws ObjectStoreException
79 {
80 return null;
81 }
82
83 public String retrieve(Serializable id) throws ObjectStoreException
84 {
85 return null;
86 }
87
88 public void store(Serializable id, String item) throws ObjectStoreException
89 {
90
91 }
92 }
93 }