@Before
 public void setUp() throws Exception {
   if (instanceFactory != null) {
     instanceFactory.shutdownAll();
   }
   instanceFactory = new TestHazelcastInstanceFactory(500);
 }
  @Test
  public void testRemovedEntry_shouldNotBeReached_afterMigration() throws Exception {
    String mapName = randomMapName();
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(2);
    MapStoreTest.SimpleMapStore<Integer, Integer> store =
        new MapStoreTest.SimpleMapStore<Integer, Integer>();
    store.store.put(1, 0);

    Config config = createConfig(mapName, store);
    HazelcastInstance node1 = factory.newHazelcastInstance(config);

    IMap<Integer, Integer> map = node1.getMap(mapName);

    map.put(1, 1);
    map.delete(1);

    HazelcastInstance node2 = factory.newHazelcastInstance(config);

    map = node2.getMap(mapName);

    Integer value = map.get(1);
    factory.shutdownAll();

    assertNull(value);
  }
  @Test
  public void test_CacheReplicationOperation_serialization() throws Exception {
    TestHazelcastInstanceFactory factory = new TestHazelcastInstanceFactory(1);
    HazelcastInstance hazelcastInstance = factory.newHazelcastInstance();

    try {
      CachingProvider provider =
          HazelcastServerCachingProvider.createCachingProvider(hazelcastInstance);
      CacheManager manager = provider.getCacheManager();

      CompleteConfiguration configuration = new MutableConfiguration();
      Cache cache1 = manager.createCache("cache1", configuration);
      Cache cache2 = manager.createCache("cache2", configuration);
      Cache cache3 = manager.createCache("cache3", configuration);

      for (int i = 0; i < 1000; i++) {
        cache1.put("key" + i, i);
        cache2.put("key" + i, i);
        cache3.put("key" + i, i);
      }

      HazelcastInstanceProxy proxy = (HazelcastInstanceProxy) hazelcastInstance;

      Field original = HazelcastInstanceProxy.class.getDeclaredField("original");
      original.setAccessible(true);

      HazelcastInstanceImpl impl = (HazelcastInstanceImpl) original.get(proxy);
      NodeEngineImpl nodeEngine = impl.node.nodeEngine;
      CacheService cacheService = nodeEngine.getService(CacheService.SERVICE_NAME);

      int partitionCount = nodeEngine.getPartitionService().getPartitionCount();

      for (int partitionId = 0; partitionId < partitionCount; partitionId++) {
        CachePartitionSegment segment = cacheService.getSegment(partitionId);

        CacheReplicationOperation operation = new CacheReplicationOperation(segment, 1);
        Data serialized = service.toData(operation);
        try {
          service.toObject(serialized);
        } catch (Exception e) {
          throw new Exception("Partition: " + partitionId, e);
        }
      }

    } finally {
      factory.shutdownAll();
    }
  }
예제 #4
0
 @Test
 public void testCustomQuorumFunctionFailsThenSuccess() throws Exception {
   Config config = new Config();
   QuorumConfig quorumConfig = new QuorumConfig();
   String quorumName = randomString();
   quorumConfig.setName(quorumName);
   quorumConfig.setEnabled(true);
   final AtomicInteger count = new AtomicInteger(1);
   quorumConfig.setQuorumFunctionImplementation(
       new QuorumFunction() {
         @Override
         public boolean apply(Collection<Member> members) {
           if (count.get() == 1) {
             count.incrementAndGet();
             return false;
           } else {
             return true;
           }
         }
       });
   config.addQuorumConfig(quorumConfig);
   String mapName = randomMapName();
   MapConfig mapConfig = new MapConfig(mapName);
   mapConfig.setQuorumName(quorumName);
   config.addMapConfig(mapConfig);
   TestHazelcastInstanceFactory f = new TestHazelcastInstanceFactory(2);
   HazelcastInstance hazelcastInstance = f.newHazelcastInstance(config);
   IMap<Object, Object> map = hazelcastInstance.getMap(mapName);
   try {
     map.put("1", "1");
     fail();
   } catch (Exception e) {
     e.printStackTrace();
   }
   HazelcastInstance hazelcastInstance2 = f.newHazelcastInstance(config);
   map.put("1", "1");
   f.shutdownAll();
 }
 @After
 public void tear() {
   cachingProvider1.close();
   cachingProvider2.close();
   factory.shutdownAll();
 }
 @After
 public void tearDown() {
   factory.shutdownAll();
 }
 @AfterClass
 public static void tearDown() {
   factory.shutdownAll();
 }