Пример #1
0
 @Test(expected = QuorumException.class)
 public void testCustomQuorumFunctionFailsForAllNodes() throws Exception {
   Config config = new Config();
   QuorumConfig quorumConfig = new QuorumConfig();
   String quorumName = randomString();
   quorumConfig.setName(quorumName);
   quorumConfig.setEnabled(true);
   quorumConfig.setQuorumFunctionImplementation(
       new QuorumFunction() {
         @Override
         public boolean apply(Collection<Member> members) {
           return false;
         }
       });
   config.addQuorumConfig(quorumConfig);
   String mapName = randomMapName();
   MapConfig mapConfig = new MapConfig(mapName);
   mapConfig.setQuorumName(quorumName);
   config.addMapConfig(mapConfig);
   TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
   HazelcastInstance h1 = factory.newHazelcastInstance(config);
   HazelcastInstance h2 = factory.newHazelcastInstance(config);
   IMap<Object, Object> map2 = h2.getMap(mapName);
   map2.put("1", "1");
 }
Пример #2
0
 @Test(timeout = 120000)
 public void testIssue583MapReplaceShouldTriggerMapStore() {
   final ConcurrentMap<String, Long> store = new ConcurrentHashMap<String, Long>();
   final MapStore<String, Long> myMapStore = new SimpleMapStore<String, Long>(store);
   Config config = getConfig();
   config
       .getMapConfig("myMap")
       .setMapStoreConfig(new MapStoreConfig().setImplementation(myMapStore));
   TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(3);
   HazelcastInstance hc = nodeFactory.newHazelcastInstance(config);
   IMap<String, Long> myMap = hc.getMap("myMap");
   myMap.put("one", 1L);
   assertEquals(1L, myMap.get("one").longValue());
   assertEquals(1L, store.get("one").longValue());
   myMap.putIfAbsent("two", 2L);
   assertEquals(2L, myMap.get("two").longValue());
   assertEquals(2L, store.get("two").longValue());
   myMap.putIfAbsent("one", 5L);
   assertEquals(1L, myMap.get("one").longValue());
   assertEquals(1L, store.get("one").longValue());
   myMap.replace("one", 1L, 111L);
   assertEquals(111L, myMap.get("one").longValue());
   assertEquals(111L, store.get("one").longValue());
   myMap.replace("one", 1L);
   assertEquals(1L, myMap.get("one").longValue());
   assertEquals(1L, store.get("one").longValue());
 }
Пример #3
0
  @Test(timeout = 120000)
  public void testIssue1142ExceptionWhenLoadAllReturnsNull() {
    Config config = getConfig();
    String mapname = "testIssue1142ExceptionWhenLoadAllReturnsNull";
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setImplementation(
        new MapStoreAdapter<String, String>() {
          @Override
          public Set<String> loadAllKeys() {
            Set keys = new HashSet();
            keys.add("key");
            return keys;
          }

          public Map loadAll(Collection keys) {
            return null;
          }
        });
    config.getMapConfig(mapname).setMapStoreConfig(mapStoreConfig);
    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(2);
    HazelcastInstance instance = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
    final IMap map = instance.getMap(mapname);
    for (int i = 0; i < 300; i++) {
      map.put(i, i);
    }
    assertEquals(300, map.size());
  }
Пример #4
0
 @Test
 public void readMulticastConfig() {
   String xml =
       "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
           + "   <group>\n"
           + "        <name>dev</name>\n"
           + "        <password>dev-pass</password>\n"
           + "    </group>\n"
           + "    <network>\n"
           + "        <port auto-increment=\"true\">5701</port>\n"
           + "        <join>\n"
           + "            <multicast enabled=\"true\" loopbackModeEnabled=\"true\">\n"
           + "                <multicast-group>224.2.2.3</multicast-group>\n"
           + "                <multicast-port>54327</multicast-port>\n"
           + "            </multicast>\n"
           + "            <tcp-ip enabled=\"false\">\n"
           + "                <interface>127.0.0.1</interface>\n"
           + "            </tcp-ip>\n"
           + "            <aws enabled=\"false\" connection-timeout-seconds=\"10\" >\n"
           + "                <access-key>access</access-key>\n"
           + "                <secret-key>secret</secret-key>\n"
           + "            </aws>\n"
           + "        </join>\n"
           + "        <interfaces enabled=\"false\">\n"
           + "            <interface>10.10.1.*</interface>\n"
           + "        </interfaces>\n"
           + "    </network>\n"
           + "</hazelcast>";
   Config config = buildConfig(xml);
   MulticastConfig mcastConfig = config.getNetworkConfig().getJoin().getMulticastConfig();
   assertTrue(mcastConfig.isEnabled());
   assertTrue(mcastConfig.isLoopbackModeEnabled());
   assertEquals("224.2.2.3", mcastConfig.getMulticastGroup());
   assertEquals(54327, mcastConfig.getMulticastPort());
 }
Пример #5
0
  @Test(timeout = 120000)
  public void testSlowStore() throws Exception {
    final TestMapStore store = new WaitingOnFirstTestMapStore();
    Config config = getConfig();
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setWriteDelaySeconds(1);
    mapStoreConfig.setImplementation(store);
    config.getMapConfig("default").setMapStoreConfig(mapStoreConfig);
    HazelcastInstance h1 = createHazelcastInstance(config);
    final IMap<Integer, Integer> map = h1.getMap("testSlowStore");
    int count = 1000;
    for (int i = 0; i < count; i++) {
      map.put(i, 1);
    }
    Thread.sleep(2000); // sleep for scheduling following puts to a different second
    for (int i = 0; i < count; i++) {
      map.put(i, 2);
    }
    for (int i = 0; i < count; i++) {
      final int index = i;
      assertTrueEventually(
          new AssertTask() {
            @Override
            public void run() throws Exception {
              final Integer valueInMap = map.get(index);
              final Integer valueInStore = (Integer) store.getStore().get(index);

              assertEquals(valueInMap, valueInStore);
            }
          });
    }
  }
  @Before
  public void setupCluster() {
    Config config = new Config();
    config.addRingBufferConfig(
        new RingbufferConfig("when*").setCapacity(100).setTimeToLiveSeconds(5));
    hazelcastFactory.newHazelcastInstance(config);
    ClientConfig clientConfig = new ClientConfig();
    clientConfig.addReliableTopicConfig(
        new ClientReliableTopicConfig("whenError_*")
            .setTopicOverloadPolicy(TopicOverloadPolicy.ERROR));
    clientConfig.addReliableTopicConfig(
        new ClientReliableTopicConfig("whenDiscardOldest_*")
            .setTopicOverloadPolicy(TopicOverloadPolicy.DISCARD_OLDEST));
    clientConfig.addReliableTopicConfig(
        new ClientReliableTopicConfig("whenDiscardNewest_*")
            .setTopicOverloadPolicy(TopicOverloadPolicy.DISCARD_NEWEST));
    clientConfig.addReliableTopicConfig(
        new ClientReliableTopicConfig("whenBlock_*")
            .setTopicOverloadPolicy(TopicOverloadPolicy.BLOCK));
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);

    serializationService = ((HazelcastClientProxy) client).getSerializationService();

    String topicName = getTestMethodName();
    topic = client.<String>getReliableTopic(topicName);

    ringbuffer = ((ClientReliableTopicProxy<String>) topic).getRingbuffer();
  }
Пример #7
0
 @Test
 public void testCaseInsensitivityOfSettings() {
   String xml =
       "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
           + "<map name=\"testCaseInsensitivity\">"
           + "<in-memory-format>BINARY</in-memory-format>     "
           + "<backup-count>1</backup-count>                 "
           + "<async-backup-count>0</async-backup-count>    "
           + "<time-to-live-seconds>0</time-to-live-seconds>"
           + "<max-idle-seconds>0</max-idle-seconds>    "
           + "<eviction-policy>NONE</eviction-policy>  "
           + "<max-size policy=\"per_partition\">0</max-size>"
           + "<eviction-percentage>25</eviction-percentage>"
           + "<merge-policy>com.hazelcast.map.merge.PassThroughMergePolicy</merge-policy>"
           + "</map>"
           + "</hazelcast>";
   final Config config = buildConfig(xml);
   final MapConfig mapConfig = config.getMapConfig("testCaseInsensitivity");
   assertTrue(mapConfig.getInMemoryFormat().equals(InMemoryFormat.BINARY));
   assertTrue(mapConfig.getEvictionPolicy().equals(EvictionPolicy.NONE));
   assertTrue(
       mapConfig
           .getMaxSizeConfig()
           .getMaxSizePolicy()
           .equals(MaxSizeConfig.MaxSizePolicy.PER_PARTITION));
 }
Пример #8
0
  @Test
  public void readVariables() {
    String xml =
        "<hazelcast>\n"
            + "    <semaphore name=\"${name}\">\n"
            + "        <initial-permits>${initial.permits}</initial-permits>\n"
            + "        <backup-count>${backupcount.part1}${backupcount.part2}</backup-count>\n"
            + "        <async-backup-count>${notreplaced}</async-backup-count>\n"
            + "    </semaphore>"
            + "</hazelcast>";
    ByteArrayInputStream bis = new ByteArrayInputStream(xml.getBytes());
    XmlConfigBuilder configBuilder = new XmlConfigBuilder(bis);

    Properties properties = new Properties();
    properties.setProperty("name", "s");
    properties.setProperty("initial.permits", "25");
    properties.setProperty("backupcount.part1", "1");
    properties.setProperty("backupcount.part2", "0");
    configBuilder.setProperties(properties);

    Config config = configBuilder.build();
    SemaphoreConfig semaphoreConfig = config.getSemaphoreConfig("s");
    assertEquals(25, semaphoreConfig.getInitialPermits());
    assertEquals(10, semaphoreConfig.getBackupCount());
    assertEquals(0, semaphoreConfig.getAsyncBackupCount());
  }
 private Config newConfig() {
   Config config = new Config();
   config.setProperty(GroupProperty.MERGE_FIRST_RUN_DELAY_SECONDS, "5");
   config.setProperty(GroupProperty.MERGE_NEXT_RUN_DELAY_SECONDS, "3");
   config.getGroupConfig().setName(generateRandomString(10));
   return config;
 }
Пример #10
0
  @Test
  public void testWaitingIndefinitely() throws InterruptedException {
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(5);
    final Config config = new Config();
    config.setProperty(GroupProperties.PROP_OPERATION_CALL_TIMEOUT_MILLIS, "2000");
    final HazelcastInstance[] instances = factory.newInstances(config);

    instances[0].getLock("testWaitingIndefinitely").lock();

    final CountDownLatch latch = new CountDownLatch(1);
    new Thread() {
      public void run() {
        try {
          // because max timeout=2000 we get timeout exception which we should not
          instances[1].getLock("testWaitingIndefinitely").lock();
          latch.countDown();
        } catch (Exception ignored) {
        }
      }
    }.start();

    // wait for enough time which is greater than max-timeout (2000)
    Thread.sleep(10000);

    instances[0].getLock("testWaitingIndefinitely").unlock();

    assertTrue(latch.await(5, TimeUnit.SECONDS));
  }
Пример #11
0
 private void testConfig2Xml2Config(String fileName) {
   final Config config = new ClasspathXmlConfig(fileName);
   final String xml = new ConfigXmlGenerator(true).generate(config);
   final Config config2 = new InMemoryXmlConfig(xml);
   assertTrue(config.isCompatible(config2));
   assertTrue(config2.isCompatible(config));
 }
Пример #12
0
  @Test
  public void testZeroResetsTTL() throws InterruptedException {
    Config cfg = new Config();
    MapConfig mc = cfg.getMapConfig("testZeroResetsTTL");
    int ttl = 5;
    mc.setTimeToLiveSeconds(ttl);
    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(1);
    HazelcastInstance instance = factory.newHazelcastInstance(cfg);
    IMap<Object, Object> map = instance.getMap("testZeroResetsTTL");
    final CountDownLatch latch = new CountDownLatch(1);
    map.addEntryListener(
        new EntryAdapter<Object, Object>() {
          public void entryEvicted(EntryEvent event) {
            latch.countDown();
          }
        },
        false);

    map.put(1, 1);
    map.put(2, 2);
    map.put(1, 2, 0, TimeUnit.SECONDS);
    latch.await(10, TimeUnit.SECONDS);
    assertNull(map.get(2));
    assertEquals(2, map.get(1));
  }
Пример #13
0
  @Test
  public void testMapRecordEviction() throws InterruptedException {
    int size = 100000;
    Config cfg = new Config();
    MapConfig mc = cfg.getMapConfig("testMapRecordEviction");
    mc.setTimeToLiveSeconds(1);
    final CountDownLatch latch = new CountDownLatch(size);
    mc.addEntryListenerConfig(
        new EntryListenerConfig()
            .setImplementation(
                new EntryAdapter() {
                  public void entryEvicted(EntryEvent event) {
                    latch.countDown();
                  }
                })
            .setLocal(true));

    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance[] instances = factory.newInstances(cfg);

    IMap map = instances[0].getMap("testMapRecordEviction");
    for (int i = 0; i < size; i++) {
      map.put(i, i);
    }
    assertTrue(latch.await(5, TimeUnit.MINUTES));
    assertEquals(0, map.size());
  }
Пример #14
0
 @Test
 public void testCustomQuorumFunctionIsPresent() throws Exception {
   Config config = new Config();
   QuorumConfig quorumConfig = new QuorumConfig();
   String quorumName = randomString();
   quorumConfig.setName(quorumName);
   quorumConfig.setEnabled(true);
   quorumConfig.setQuorumFunctionImplementation(
       new QuorumFunction() {
         @Override
         public boolean apply(Collection<Member> members) {
           return false;
         }
       });
   config.addQuorumConfig(quorumConfig);
   String mapName = randomMapName();
   MapConfig mapConfig = new MapConfig(mapName);
   mapConfig.setQuorumName(quorumName);
   config.addMapConfig(mapConfig);
   HazelcastInstance hazelcastInstance = createHazelcastInstance(config);
   IMap<Object, Object> map = hazelcastInstance.getMap(mapName);
   try {
     map.put("1", "1");
     fail();
   } catch (Exception e) {
   }
   Quorum quorum = hazelcastInstance.getQuorumService().getQuorum(quorumName);
   assertFalse(quorum.isPresent());
 }
Пример #15
0
  private HazelcastInstance defaultConfig(final ClusteringConfig clusteringConfig) {
    final Config hazelcastConfig = new Config();

    hazelcastConfig.setGroupConfig(
        new GroupConfig(clusteringConfig.getClusterName(), clusteringConfig.getClusterPassword()));

    final NetworkConfig networkConfig = new NetworkConfig();

    networkConfig.setPort(clusteringConfig.getMulticastPort());

    final JoinConfig joinConfig = new JoinConfig();

    final MulticastConfig multicastConfig = new MulticastConfig();

    multicastConfig.setMulticastPort(clusteringConfig.getMulticastPort());

    multicastConfig.setMulticastGroup(clusteringConfig.getMulticastGroup());

    joinConfig.setMulticastConfig(multicastConfig);

    networkConfig.setJoin(joinConfig);

    hazelcastConfig.setNetworkConfig(networkConfig);

    return Hazelcast.newHazelcastInstance(hazelcastConfig);
  }
 private HazelcastInstance newInstance() {
   final Config config = new Config();
   final MapConfig mapConfig = new MapConfig(MAP_NAME);
   mapConfig.setBackupCount(2);
   config.addMapConfig(mapConfig);
   return instanceFactory.newHazelcastInstance(config);
 }
Пример #17
0
  private void multicastJoin(int count, final boolean sleep) throws InterruptedException {
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(count);

    final Config config = new Config();
    config.setProperty("hazelcast.wait.seconds.before.join", "5");
    config.getNetworkConfig().getJoin().getMulticastConfig().setMulticastTimeoutSeconds(25);
    final ConcurrentMap<Integer, HazelcastInstance> map =
        new ConcurrentHashMap<Integer, HazelcastInstance>();
    final CountDownLatch latch = new CountDownLatch(count);
    final ExecutorService ex = Executors.newCachedThreadPool();
    for (int i = 0; i < count; i++) {
      final int index = i;
      ex.execute(
          new Runnable() {
            public void run() {
              if (sleep) {
                try {
                  Thread.sleep((int) (1000 * Math.random()));
                } catch (InterruptedException ignored) {
                }
              }
              HazelcastInstance h = nodeFactory.newHazelcastInstance(config);
              map.put(index, h);
              latch.countDown();
            }
          });
    }
    assertOpenEventually(latch);
    for (HazelcastInstance h : map.values()) {
      assertEquals(count, h.getCluster().getMembers().size());
    }
    ex.shutdown();
  }
Пример #18
0
  @Test
  public void testHotRestart() {
    String dir = "/mnt/hot-restart-root/";
    int validationTimeout = 13131;
    int dataLoadTimeout = 45454;
    String xml =
        "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
            + "<hot-restart-persistence enabled=\"true\">"
            + "<base-dir>"
            + dir
            + "</base-dir>"
            + "<validation-timeout-seconds>"
            + validationTimeout
            + "</validation-timeout-seconds>"
            + "<data-load-timeout-seconds>"
            + dataLoadTimeout
            + "</data-load-timeout-seconds>"
            + "</hot-restart-persistence>\n"
            + "</hazelcast>";

    Config config = new InMemoryXmlConfig(xml);
    HotRestartPersistenceConfig hotRestartPersistenceConfig =
        config.getHotRestartPersistenceConfig();
    assertTrue(hotRestartPersistenceConfig.isEnabled());
    assertEquals(
        new File(dir).getAbsolutePath(),
        hotRestartPersistenceConfig.getBaseDir().getAbsolutePath());
    assertEquals(validationTimeout, hotRestartPersistenceConfig.getValidationTimeoutSeconds());
    assertEquals(dataLoadTimeout, hotRestartPersistenceConfig.getDataLoadTimeoutSeconds());
  }
Пример #19
0
  @Test
  public void readReliableTopic() {
    String xml =
        "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
            + "    <reliable-topic name=\"custom\">\n"
            + "           <read-batch-size>35</read-batch-size>\n"
            + "           <statistics-enabled>false</statistics-enabled>\n"
            + "           <topic-overload-policy>DISCARD_OLDEST</topic-overload-policy>\n"
            + "           <message-listeners>"
            + "               <message-listener>MessageListenerImpl</message-listener>"
            + "           </message-listeners>"
            + "    </reliable-topic>\n"
            + "</hazelcast>";

    Config config = buildConfig(xml);

    ReliableTopicConfig topicConfig = config.getReliableTopicConfig("custom");

    assertEquals(35, topicConfig.getReadBatchSize());
    assertFalse(topicConfig.isStatisticsEnabled());
    assertEquals(TopicOverloadPolicy.DISCARD_OLDEST, topicConfig.getTopicOverloadPolicy());

    // checking listener configuration
    assertEquals(1, topicConfig.getMessageListenerConfigs().size());
    ListenerConfig listenerConfig = topicConfig.getMessageListenerConfigs().get(0);
    assertEquals("MessageListenerImpl", listenerConfig.getClassName());
    assertNull(listenerConfig.getImplementation());
  }
Пример #20
0
 @Test
 public void testMapWanReplicationRef() {
   String mapName = "testMapWanReplicationRef";
   String refName = "test";
   String mergePolicy = "TestMergePolicy";
   String xml =
       HAZELCAST_START_TAG
           + "  <map name=\""
           + mapName
           + "\">\n"
           + "    <wan-replication-ref name=\"test\">\n"
           + "      <merge-policy>TestMergePolicy</merge-policy>\n"
           + "      <filters>\n"
           + "        <filter-impl>com.example.SampleFilter</filter-impl>\n"
           + "      </filters>\n"
           + "    </wan-replication-ref>\n"
           + "  </map>\n"
           + "</hazelcast>";
   final Config config = buildConfig(xml);
   System.out.println("config = " + config);
   WanReplicationRef wanRef = config.getMapConfig(mapName).getWanReplicationRef();
   assertEquals(refName, wanRef.getName());
   assertEquals(mergePolicy, wanRef.getMergePolicy());
   assertTrue(wanRef.isRepublishingEnabled());
   assertEquals(1, wanRef.getFilters().size());
   assertEquals("com.example.SampleFilter", wanRef.getFilters().get(0));
 }
Пример #21
0
 @Test
 public void testConfigurationWithFile() throws Exception {
   URL url = getClass().getClassLoader().getResource("hazelcast-default.xml");
   System.setProperty("hazelcast.config", url.getFile());
   Config config = new XmlConfigBuilder().build();
   assertEquals(url, config.getConfigurationUrl());
 }
Пример #22
0
  @Test
  public void testWaitingIndefinitely() throws InterruptedException {
    final Config config = new Config();
    config.setProperty(GroupProperties.PROP_OPERATION_CALL_TIMEOUT_MILLIS, "3000");

    TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(2);
    final HazelcastInstance[] instances = factory.newInstances(config);

    // need to warm-up partitions,
    // since waiting for lock backup can take up to 5 seconds
    // and that may cause OperationTimeoutException with "No response for 4000 ms" error.
    warmUpPartitions(instances);

    final String name = "testWaitingIndefinitely";
    ILock lock = instances[0].getLock(name);
    lock.lock();

    final CountDownLatch latch = new CountDownLatch(1);
    new Thread() {
      public void run() {
        try {
          // because max timeout=3000 we get timeout exception which we should not
          instances[1].getLock(name).lock();
          latch.countDown();
        } catch (Exception ignored) {
        }
      }
    }.start();

    // wait for enough time which is greater than max-timeout (3000)
    sleepSeconds(10);
    lock.unlock();

    assertTrue(latch.await(20, TimeUnit.SECONDS));
  }
Пример #23
0
 @Test
 public void testWanConfig() {
   String xml =
       "<hazelcast xmlns=\"http://www.hazelcast.com/schema/config\">\n"
           + "<wan-replication name=\"my-wan-cluster\" snapshot-enabled=\"true\">\n"
           + "    <target-cluster group-name=\"test-cluster-1\" group-password=\"test-pass\">\n"
           + "       <replication-impl>com.hazelcast.enterprise.wan.replication.WanBatchReplication</replication-impl>\n"
           + "       <end-points>\n"
           + "          <address>20.30.40.50:5701</address>\n"
           + "          <address>20.30.40.50:5702</address>\n"
           + "       </end-points>\n"
           + "    </target-cluster>\n"
           + "</wan-replication>\n"
           + "</hazelcast>";
   Config config = buildConfig(xml);
   WanReplicationConfig wanConfig = config.getWanReplicationConfig("my-wan-cluster");
   assertNotNull(wanConfig);
   assertTrue(wanConfig.isSnapshotEnabled());
   List<WanTargetClusterConfig> targetClusterConfigs = wanConfig.getTargetClusterConfigs();
   assertEquals(1, targetClusterConfigs.size());
   WanTargetClusterConfig targetClusterConfig = targetClusterConfigs.get(0);
   assertEquals("test-cluster-1", targetClusterConfig.getGroupName());
   assertEquals("test-pass", targetClusterConfig.getGroupPassword());
   List<String> targetEndpoints = targetClusterConfig.getEndpoints();
   assertEquals(2, targetEndpoints.size());
   assertTrue(targetEndpoints.contains("20.30.40.50:5701"));
   assertTrue(targetEndpoints.contains("20.30.40.50:5702"));
 }
  @Test
  public void testDataIntegrity() throws InterruptedException {
    setLoggingLog4j();
    System.out.println("nodeCount = " + nodeCount);
    System.out.println("operations = " + operations);
    System.out.println("keyCount = " + keyCount);
    Config config = new Config();
    config.getReplicatedMapConfig("test").setReplicationDelayMillis(0);
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(nodeCount);
    final HazelcastInstance[] instances = factory.newInstances(config);
    String replicatedMapName = "test";
    final List<ReplicatedMap> maps = createMapOnEachInstance(instances, replicatedMapName);
    ArrayList<Integer> keys = generateRandomIntegerList(keyCount);
    Thread[] threads = createThreads(nodeCount, maps, keys, operations);
    for (Thread thread : threads) {
      thread.start();
    }
    for (Thread thread : threads) {
      thread.join();
    }
    for (int i = 0; i < keyCount; i++) {
      final String key = "foo-" + keys.get(i);
      assertTrueEventually(
          new AssertTask() {
            @Override
            public void run() throws Exception {
              System.out.println("---------------------");
              System.out.println("key = " + key);
              printValues();
              assertValuesAreEqual();
            }

            private void printValues() throws Exception {
              for (int j = 0; j < maps.size(); j++) {
                ReplicatedMap map = maps.get(j);
                System.out.println(
                    "value["
                        + j
                        + "] = "
                        + map.get(key)
                        + " , store version : "
                        + getStore(map, key).getVersion());
              }
            }

            private void assertValuesAreEqual() {
              for (int i = 0; i < maps.size() - 1; i++) {
                ReplicatedMap map1 = maps.get(i);
                ReplicatedMap map2 = maps.get(i + 1);
                Object v1 = map1.get(key);
                Object v2 = map2.get(key);
                assertNotNull(v1);
                assertNotNull(v2);
                assertEquals(v1, v2);
              }
            }
          },
          120);
    }
  }
Пример #25
0
  @Test(timeout = 120000)
  public void testInitialLoadModeEagerMultipleThread() {
    final String mapName = "default";
    final int instanceCount = 2;
    final int size = 10000;
    final TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(instanceCount);
    final CountDownLatch countDownLatch = new CountDownLatch(instanceCount - 1);
    final Config config = getConfig();
    GroupConfig groupConfig = new GroupConfig("testEager");
    config.setGroupConfig(groupConfig);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(new SimpleMapLoader(size, true));
    mapStoreConfig.setInitialLoadMode(MapStoreConfig.InitialLoadMode.EAGER);
    config.getMapConfig(mapName).setMapStoreConfig(mapStoreConfig);

    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    Runnable runnable =
        new Runnable() {
          public void run() {
            HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);
            final IMap<Object, Object> map = instance2.getMap(mapName);
            assertEquals(size, map.size());
            countDownLatch.countDown();
          }
        };
    new Thread(runnable).start();

    assertOpenEventually(countDownLatch, 120);
    IMap map = instance1.getMap(mapName);
    assertEquals(size, map.size());
  }
  @Test
  public void testReplicatedMapConfig() {
    assertNotNull(config);
    assertEquals(1, config.getReplicatedMapConfigs().size());

    ReplicatedMapConfig replicatedMapConfig = config.getReplicatedMapConfig("replicatedMap");
    assertNotNull(replicatedMapConfig);
    assertEquals("replicatedMap", replicatedMapConfig.getName());
    assertEquals(200, replicatedMapConfig.getReplicationDelayMillis());
    assertEquals(16, replicatedMapConfig.getConcurrencyLevel());
    assertEquals(InMemoryFormat.OBJECT, replicatedMapConfig.getInMemoryFormat());
    assertFalse(replicatedMapConfig.isStatisticsEnabled());
    assertFalse(replicatedMapConfig.isAsyncFillup());

    replicatedMapConfig.getListenerConfigs();
    for (ListenerConfig listener : replicatedMapConfig.getListenerConfigs()) {
      if (listener.getClassName() != null) {
        assertNull(listener.getImplementation());
        assertTrue(listener.isIncludeValue());
        assertFalse(listener.isLocal());
      } else {
        assertNotNull(listener.getImplementation());
        assertEquals(entryListener, listener.getImplementation());
        assertTrue(listener.isLocal());
        assertTrue(listener.isIncludeValue());
      }
    }
  }
Пример #27
0
  @Test(timeout = 120000)
  public void testIssue991EvictedNullIssue() throws InterruptedException {
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    mapStoreConfig.setEnabled(true);
    mapStoreConfig.setImplementation(
        new MapLoader<String, String>() {
          @Override
          public String load(String key) {
            return null;
          }

          @Override
          public Map<String, String> loadAll(Collection<String> keys) {
            return null;
          }

          @Override
          public Set<String> loadAllKeys() {
            return null;
          }
        });
    Config config = getConfig();
    config.getMapConfig("testIssue991EvictedNullIssue").setMapStoreConfig(mapStoreConfig);
    HazelcastInstance hc = createHazelcastInstance(config);
    IMap<Object, Object> map = hc.getMap("testIssue991EvictedNullIssue");
    map.get("key");
    assertNull(map.get("key"));
    map.put("key", "value");
    Thread.sleep(2000);
    assertEquals("value", map.get("key"));
  }
 private BasicBackPressureService newEnabledBackPressureService() {
   Config config = new Config();
   config.setProperty(GroupProperties.PROP_BACKPRESSURE_ENABLED, "true");
   config.setProperty(GroupProperties.PROP_BACKPRESSURE_SYNCWINDOW, "" + SYNC_WINDOW);
   GroupProperties groupProperties = new GroupProperties(config);
   return new BasicBackPressureService(groupProperties, logger);
 }
Пример #29
0
  @Test(timeout = 120000)
  public void testMapStoreNotCalledFromEntryProcessorBackup() throws Exception {
    final String mapName = "testMapStoreNotCalledFromEntryProcessorBackup_" + randomString();
    final int instanceCount = 2;
    Config config = getConfig();
    // Configure map with one backup and dummy map store
    MapConfig mapConfig = config.getMapConfig(mapName);
    mapConfig.setBackupCount(1);
    MapStoreConfig mapStoreConfig = new MapStoreConfig();
    MapStoreWithStoreCount mapStore = new MapStoreWithStoreCount(1, 120);
    mapStoreConfig.setImplementation(mapStore);
    mapConfig.setMapStoreConfig(mapStoreConfig);

    TestHazelcastInstanceFactory nodeFactory = createHazelcastInstanceFactory(instanceCount);
    HazelcastInstance instance1 = nodeFactory.newHazelcastInstance(config);
    HazelcastInstance instance2 = nodeFactory.newHazelcastInstance(config);

    final IMap<String, String> map = instance1.getMap(mapName);
    final String key = "key";
    final String value = "value";
    // executeOnKey
    map.executeOnKey(key, new ValueSetterEntryProcessor(value));
    mapStore.awaitStores();

    assertEquals(value, map.get(key));
    assertEquals(1, mapStore.getCount());
  }
Пример #30
0
  @Test
  public void testClientListenerDisconnected() throws InterruptedException {
    Config config = new Config();
    config.setProperty(GroupProperties.PROP_IO_THREAD_COUNT, "1");

    final HazelcastInstance hz = Hazelcast.newHazelcastInstance(config);
    final HazelcastInstance hz2 = Hazelcast.newHazelcastInstance(config);

    int clientCount = 10;
    ClientDisconnectedListenerLatch listenerLatch =
        new ClientDisconnectedListenerLatch(2 * clientCount);
    hz.getClientService().addClientListener(listenerLatch);
    hz2.getClientService().addClientListener(listenerLatch);

    Collection<HazelcastInstance> clients = new LinkedList<HazelcastInstance>();
    for (int i = 0; i < clientCount; i++) {
      HazelcastInstance client = HazelcastClient.newHazelcastClient();
      IMap<Object, Object> map = client.getMap(randomMapName());

      map.addEntryListener(new EntryAdapter<Object, Object>(), true);
      map.put(generateKeyOwnedBy(hz), "value");
      map.put(generateKeyOwnedBy(hz2), "value");

      clients.add(client);
    }

    ExecutorService ex = Executors.newFixedThreadPool(4);
    try {
      for (final HazelcastInstance client : clients) {
        ex.execute(
            new Runnable() {
              @Override
              public void run() {
                client.shutdown();
              }
            });
      }

      assertOpenEventually(listenerLatch, 30);

      assertTrueEventually(
          new AssertTask() {
            @Override
            public void run() throws Exception {
              assertEquals(0, hz.getClientService().getConnectedClients().size());
            }
          },
          10);
      assertTrueEventually(
          new AssertTask() {
            @Override
            public void run() throws Exception {
              assertEquals(0, hz2.getClientService().getConnectedClients().size());
            }
          },
          10);
    } finally {
      ex.shutdown();
    }
  }