use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class FrozenPartitionTableTest method partitionTable_isFrozen_whenMemberReJoins_duringClusterStateIsFrozen.
@Test
public void partitionTable_isFrozen_whenMemberReJoins_duringClusterStateIsFrozen() {
Config config = new Config();
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(4);
HazelcastInstance[] instances = factory.newInstances(config, 3);
HazelcastInstance hz1 = instances[0];
HazelcastInstance hz2 = instances[1];
HazelcastInstance hz3 = instances[2];
Address hz3Address = getNode(hz3).getThisAddress();
warmUpPartitions(instances);
final Map<Integer, List<Address>> partitionTable = getPartitionTable(hz1);
changeClusterStateEventually(hz2, ClusterState.FROZEN);
terminateInstance(hz3);
hz3 = factory.newHazelcastInstance(hz3Address);
assertClusterSizeEventually(3, hz1);
assertClusterSizeEventually(3, hz2);
assertClusterSizeEventually(3, hz3);
for (HazelcastInstance instance : Arrays.asList(hz1, hz2, hz3)) {
final HazelcastInstance hz = instance;
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertPartitionTablesSame(partitionTable, getPartitionTable(hz));
}
});
}
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class IOBalancerMemoryLeakTest method testMemoryLeak_with_SocketConnections.
@Test
public void testMemoryLeak_with_SocketConnections() throws IOException {
Config config = new Config();
config.getGroupConfig().setName(randomName());
config.setProperty(GroupProperty.IO_BALANCER_INTERVAL_SECONDS.getName(), "1");
HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
final Address address = instance.getCluster().getLocalMember().getAddress();
int threadCount = 10;
final int connectionCountPerThread = 100;
Runnable runnable = new Runnable() {
public void run() {
for (int i = 0; i < connectionCountPerThread; i++) {
Socket socket = null;
try {
socket = new Socket(address.getHost(), address.getPort());
socket.getOutputStream().write(Protocols.CLUSTER.getBytes());
sleepMillis(1000);
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
};
Thread[] threads = new Thread[threadCount];
for (int i = 0; i < threadCount; i++) {
threads[i] = new Thread(runnable);
threads[i].start();
}
assertJoinable(threads);
TcpIpConnectionManager connectionManager = (TcpIpConnectionManager) getConnectionManager(instance);
final IOBalancer ioBalancer = connectionManager.getIoBalancer();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
LoadTracker inLoadTracker = ioBalancer.getInLoadTracker();
LoadTracker outLoadTracker = ioBalancer.getOutLoadTracker();
int inHandlerSize = inLoadTracker.getHandlers().size();
int outHandlerSize = outLoadTracker.getHandlers().size();
int inHandlerEventsCount = inLoadTracker.getHandlerEventsCounter().keySet().size();
int outHandlerEventsCount = outLoadTracker.getHandlerEventsCounter().keySet().size();
int inLastEventsCount = inLoadTracker.getLastEventCounter().keySet().size();
int outLastEventsCount = outLoadTracker.getLastEventCounter().keySet().size();
Assert.assertEquals(0, inHandlerSize);
Assert.assertEquals(0, outHandlerSize);
Assert.assertEquals(0, inHandlerEventsCount);
Assert.assertEquals(0, outHandlerEventsCount);
Assert.assertEquals(0, inLastEventsCount);
Assert.assertEquals(0, outLastEventsCount);
}
});
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class GracefulShutdownTest method newConfig.
private Config newConfig() {
Config config = new Config();
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "6");
config.setProperty(GroupProperty.PARTITION_MIGRATION_INTERVAL.getName(), "1");
return config;
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class MapListenerTest method main.
public static void main(String[] args) throws InterruptedException {
// create Hazelcast instance
Config config = new Config();
config.setInstanceName("hz-maplistener");
config.getNetworkConfig().getJoin().getMulticastConfig().setEnabled(false);
config.getNetworkConfig().getInterfaces().setInterfaces(Arrays.asList(new String[] { "127.0.0.1" }));
HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
IMap<String, Person> map = hz.getMap("map");
MapListener listener = new AllListener();
map.addEntryListener(listener, new SqlPredicate("age > " + AGE_THRESHOLD), true);
MapRandomizer mapRandomizer = new MapRandomizer(map);
Thread t = new Thread(mapRandomizer);
t.start();
// let it run for 1 minute
Thread.sleep(60000);
mapRandomizer.setRunning(false);
// assertions
assertCount(ENTRIES, ENTRIES_OBSERVED, "entries");
assertCount(EXITS, EXITS_OBSERVED, "exits");
// dumpMap(map);
hz.shutdown();
}
use of com.hazelcast.config.Config in project hazelcast by hazelcast.
the class EvictionMaxSizePolicyTest method createConfig.
Config createConfig(MaxSizeConfig.MaxSizePolicy maxSizePolicy, int maxSize, String mapName) {
Config config = getConfig();
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), String.valueOf(PARTITION_COUNT));
MaxSizeConfig msc = new MaxSizeConfig();
msc.setMaxSizePolicy(maxSizePolicy);
msc.setSize(maxSize);
MapConfig mapConfig = config.getMapConfig(mapName);
mapConfig.setEvictionPolicy(EvictionPolicy.LRU);
mapConfig.setEvictionPercentage(25);
mapConfig.setMaxSizeConfig(msc);
mapConfig.setMinEvictionCheckMillis(0L);
return config;
}
Aggregations