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.junit4.AbstractMuleTestCase;
17
18 import java.io.Serializable;
19
20 import org.junit.Test;
21
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertTrue;
24
25 public class MonitoredObjectStoreTestCase extends AbstractMuleTestCase
26 {
27 private static final int EXPIRATION_INTERVAL = 500;
28
29 @Test
30 public void testShutdownWithHangingExpireThread() throws Exception
31 {
32 ExpiringStore store = createExpiringStore();
33
34
35 Thread.sleep(EXPIRATION_INTERVAL * 2);
36
37
38
39 store.dispose();
40
41 assertTrue(store.expireStarted);
42 assertFalse(store.expireFinished);
43 }
44
45 private ExpiringStore createExpiringStore() throws InitialisationException
46 {
47 ExpiringStore store = new ExpiringStore();
48 store.setExpirationInterval(EXPIRATION_INTERVAL);
49 store.initialise();
50
51 return store;
52 }
53
54 private static class ExpiringStore extends AbstractMonitoredObjectStore<String>
55 {
56 protected boolean expireStarted = false;
57 protected boolean expireFinished = false;
58
59 public ExpiringStore()
60 {
61 super();
62 }
63
64 @Override
65 protected void expire()
66 {
67 try
68 {
69 expireStarted = true;
70 Thread.sleep(EXPIRATION_INTERVAL * 10);
71 expireFinished = true;
72 }
73 catch (InterruptedException e)
74 {
75 throw new RuntimeException("expire was interrupted", e);
76 }
77 }
78
79 public boolean contains(Serializable id) throws ObjectStoreNotAvaliableException
80 {
81 return false;
82 }
83
84 public String remove(Serializable id) throws ObjectStoreException
85 {
86 return null;
87 }
88
89 public String retrieve(Serializable id) throws ObjectStoreException
90 {
91 return null;
92 }
93
94 public void store(Serializable id, String item) throws ObjectStoreException
95 {
96
97 }
98
99
100 public boolean isPersistent()
101 {
102 return false;
103 }
104 }
105 }