-
Notifications
You must be signed in to change notification settings - Fork 277
/
HazelcastWithCustomSerializersAndOffloadableExecutorTest.java
81 lines (69 loc) · 2.99 KB
/
HazelcastWithCustomSerializersAndOffloadableExecutorTest.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
74
75
76
77
78
79
80
81
package io.github.bucket4j.hazelcast;
import com.hazelcast.config.Config;
import com.hazelcast.config.JoinConfig;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;
import io.github.bucket4j.distributed.proxy.ClientSideConfig;
import io.github.bucket4j.distributed.proxy.ProxyManager;
import io.github.bucket4j.grid.hazelcast.HazelcastProxyManager;
import io.github.bucket4j.tck.AbstractDistributedBucketTest;
import org.gridkit.nanocloud.Cloud;
import org.gridkit.nanocloud.CloudFactory;
import org.gridkit.nanocloud.VX;
import org.gridkit.vicluster.ViNode;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import java.io.Serializable;
import java.util.UUID;
public class HazelcastWithCustomSerializersAndOffloadableExecutorTest extends AbstractDistributedBucketTest<String> {
private static IMap<String, byte[]> map;
private static Cloud cloud;
private static ViNode server;
private static HazelcastInstance hazelcastInstance;
@BeforeClass
public static void setup() {
// start separated JVM on current host
cloud = CloudFactory.createCloud();
cloud.node("**").x(VX.TYPE).setLocal();
server = cloud.node("stateful-hazelcast-server");
server.exec((Runnable & Serializable) () -> {
Config config = new Config();
HazelcastProxyManager.addCustomSerializers(config.getSerializationConfig(), 10_000);
JoinConfig joinConfig = config.getNetworkConfig().getJoin();
joinConfig.getMulticastConfig().setEnabled(false);
joinConfig.getTcpIpConfig().setEnabled(true);
joinConfig.getTcpIpConfig().addMember("127.0.0.1:5702");
config.setLiteMember(false);
HazelcastInstance hazelcastInstance = Hazelcast.newHazelcastInstance(config);
hazelcastInstance.getMap("my_buckets");
});
// start hazelcast client which works inside current JVM and does not hold data
Config config = new Config();
JoinConfig joinConfig = config.getNetworkConfig().getJoin();
joinConfig.getMulticastConfig().setEnabled(false);
joinConfig.getTcpIpConfig().setEnabled(true);
joinConfig.getTcpIpConfig().addMember("127.0.0.1:5701");
HazelcastProxyManager.addCustomSerializers(config.getSerializationConfig(), 10_000);
config.setLiteMember(true);
hazelcastInstance = Hazelcast.newHazelcastInstance(config);
map = hazelcastInstance.getMap("my_buckets");
}
@AfterClass
public static void shutdown() {
if (hazelcastInstance != null) {
hazelcastInstance.shutdown();
}
if (cloud != null) {
cloud.shutdown();
}
}
@Override
protected ProxyManager<String> getProxyManager() {
return new HazelcastProxyManager<>(map, ClientSideConfig.getDefault(), "my-executor");
}
@Override
protected String generateRandomKey() {
return UUID.randomUUID().toString();
}
}