-
Notifications
You must be signed in to change notification settings - Fork 6
/
GarbageCollectWholeCluster.java
73 lines (53 loc) · 2.56 KB
/
GarbageCollectWholeCluster.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
68
69
70
71
72
73
package com.benstopford.coherence.bootstrap.morecomplex.sizing;
import com.benstopford.coherence.bootstrap.structures.framework.cluster.ClusterRunner;
import com.benstopford.coherence.bootstrap.structures.tools.jmx.ClusterGC;
import com.benstopford.coherence.bootstrap.structures.util.GcInformation;
import com.sun.management.GarbageCollectorMXBean;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;
public class GarbageCollectWholeCluster extends ClusterRunner {
@Test
public void shouldCollectLocalJvmViaJmx() throws Exception {
startLocalJMXServer(10001);
long initialGcCount = GcInformation.getOldGenBean().getCollectionCount();
long gcCount = 10;
for (int i = 0; i < gcCount; i++) {
new ClusterGC().run(new String[]{"localhost:10001"});
}
assertThat(GcInformation.getOldGenBean().getCollectionCount() - initialGcCount, is(gcCount));
}
@Test
public void shouldCollectMultipleRemoteJvmsViaJmx() throws Exception {
startBasicCacheProcessWithJMX(10002);
startBasicCacheProcessWithJMX(10003);
startDataDisabledExtendProxy();
System.gc();
long intial10002 = getOldGenCollectionCount("10002");
long intial10003 = getOldGenCollectionCount("10003");
new ClusterGC().run(new String[]{"localhost:10002"});
assertThat(getOldGenCollectionCount("10002"), is(intial10002 + 1));
assertThat(getOldGenCollectionCount("10003"), is(intial10003));
new ClusterGC().run(new String[]{"localhost:10003"});
assertThat(getOldGenCollectionCount("10002"), is(intial10002 + 1));
assertThat(getOldGenCollectionCount("10003"), is(intial10003 + 1));
new ClusterGC().run(new String[]{"localhost:10002","localhost:10003"});
assertThat(getOldGenCollectionCount("10002"), is(intial10002 + 2));
assertThat(getOldGenCollectionCount("10003"), is(intial10003 + 2));
}
private long getOldGenCollectionCount(String port) throws Exception {
long collectionCount = -1;
List<GarbageCollectorMXBean> beans = new ClusterGC().getGCMbean("localhost", port);
for (GarbageCollectorMXBean bean : beans) {
if (isOldGen(bean)) {
collectionCount = bean.getCollectionCount();
}
}
return collectionCount;
}
private boolean isOldGen(GarbageCollectorMXBean bean) {
return Arrays.asList(bean.getMemoryPoolNames()).contains("PS Old Gen");
}
}