Search in sources :

Example 6 with Config

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));
            }
        });
    }
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) Config(com.hazelcast.config.Config) AssertTask(com.hazelcast.test.AssertTask) ArrayList(java.util.ArrayList) List(java.util.List) TestHazelcastInstanceFactory(com.hazelcast.test.TestHazelcastInstanceFactory) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 7 with Config

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);
        }
    });
}
Also used : Address(com.hazelcast.nio.Address) Config(com.hazelcast.config.Config) IOException(java.io.IOException) IOException(java.io.IOException) HazelcastInstance(com.hazelcast.core.HazelcastInstance) AssertTask(com.hazelcast.test.AssertTask) TcpIpConnectionManager(com.hazelcast.nio.tcp.TcpIpConnectionManager) Socket(java.net.Socket) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test)

Example 8 with Config

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;
}
Also used : Config(com.hazelcast.config.Config)

Example 9 with 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();
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) MapListener(com.hazelcast.map.listener.MapListener) Config(com.hazelcast.config.Config) SqlPredicate(com.hazelcast.query.SqlPredicate)

Example 10 with Config

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;
}
Also used : MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MaxSizeConfig(com.hazelcast.config.MaxSizeConfig) MapConfig(com.hazelcast.config.MapConfig) Config(com.hazelcast.config.Config) MapConfig(com.hazelcast.config.MapConfig)

Aggregations

Config (com.hazelcast.config.Config)2458 Test (org.junit.Test)1570 HazelcastInstance (com.hazelcast.core.HazelcastInstance)1465 QuickTest (com.hazelcast.test.annotation.QuickTest)1286 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)1003 MapConfig (com.hazelcast.config.MapConfig)599 TestHazelcastInstanceFactory (com.hazelcast.test.TestHazelcastInstanceFactory)497 MapStoreConfig (com.hazelcast.config.MapStoreConfig)300 NearCacheConfig (com.hazelcast.config.NearCacheConfig)270 Before (org.junit.Before)242 ClientConfig (com.hazelcast.client.config.ClientConfig)228 SlowTest (com.hazelcast.test.annotation.SlowTest)204 NightlyTest (com.hazelcast.test.annotation.NightlyTest)186 CountDownLatch (java.util.concurrent.CountDownLatch)182 IndexConfig (com.hazelcast.config.IndexConfig)162 JoinConfig (com.hazelcast.config.JoinConfig)142 ParallelTest (com.hazelcast.test.annotation.ParallelTest)141 AssertTask (com.hazelcast.test.AssertTask)131 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)126 CacheSimpleConfig (com.hazelcast.config.CacheSimpleConfig)125