-
Notifications
You must be signed in to change notification settings - Fork 6
/
ParitionListenerForDataLoss.java
executable file
·67 lines (54 loc) · 2.42 KB
/
ParitionListenerForDataLoss.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.benstopford.coherence.bootstrap.basic;
import com.benstopford.coherence.bootstrap.structures.tools.MyPartitionListener;
import com.benstopford.coherence.bootstrap.structures.framework.cluster.ClusterRunner;
import com.tangosol.net.NamedCache;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.io.IOException;
import static junit.framework.Assert.assertEquals;
import static junit.framework.Assert.assertTrue;
/**
* BTS, 12-May-2008
*/
public class ParitionListenerForDataLoss extends ClusterRunner {
/**
* A PartitionListener tells you that a data partition has been lost. This is really important as otherwise you
* simply don't know if the cluster is in a good shape of not. Patition Listeners are used to detect a
* repartitioning event. That is to say that if a node is lost, say the process dies or the Cache Service restarts
* itself etc, Coherence will restore the data from its backup copy.
*/
@Test
public void dataLossShouldTriggerPartitionListenerActivation() throws IOException, InterruptedException {
String dataEnabledConfig = "config/basic-cache-with-a-partition-listener-local-storage-true.xml";
//create 3 external data enabled processes
Process nodeToBeKilled = startCoherenceProcess(dataEnabledConfig);
Process nodeToBeKilled2 = startCoherenceProcess(dataEnabledConfig);
startCoherenceProcess(dataEnabledConfig);
//Ensure this VM is data disabled for this cache service
NamedCache cache = getCache("config/basic-cache-with-local-storage-false.xml","foo");
Thread.sleep(2000);
//make sure we have clustered all 4 nodes
assertEquals(4, cache.getCacheService().getCluster().getMemberSet().size());
//add some data
addData(cache, 100);
nodeToBeKilled.destroy();
nodeToBeKilled2.destroy();
Thread.sleep(5000);
assertTrue(MyPartitionListener.CLUSTER_DATA_LOSS_FLAG_FILE.exists());
}
@Before
public void setUp() throws Exception {
super.setUp();
File flagFile = MyPartitionListener.CLUSTER_DATA_LOSS_FLAG_FILE;
if (flagFile.exists()) {
flagFile.delete();
System.out.println("deleted file");
}
}
@After
public void tearDown() throws Exception {
super.tearDown();
}
}