use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class EntryProcessorTest method testIssue7631_emptyKeysSupported.
@Test
public void testIssue7631_emptyKeysSupported() {
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory();
IMap<Object, Object> map = factory.newHazelcastInstance().getMap(MAP_NAME);
assertEquals(emptyMap(), map.executeOnEntries(new NoOpEntryProcessor()));
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class QueryCacheRecoveryUponEventLossTest method testForceConsistency.
@Test
public void testForceConsistency() {
TestHazelcastInstanceFactory instanceFactory = createHazelcastInstanceFactory(3);
String mapName = randomString();
String queryCacheName = randomString();
Config config = new Config();
config.setProperty(GroupProperty.PARTITION_COUNT.getName(), "1");
QueryCacheConfig queryCacheConfig = new QueryCacheConfig(queryCacheName);
queryCacheConfig.setBatchSize(1111);
queryCacheConfig.setDelaySeconds(3);
MapConfig mapConfig = config.getMapConfig(mapName);
mapConfig.addQueryCacheConfig(queryCacheConfig);
mapConfig.setBackupCount(0);
HazelcastInstance node = instanceFactory.newHazelcastInstance(config);
HazelcastInstance node2 = instanceFactory.newHazelcastInstance(config);
setTestSequencer(node, 9);
setTestSequencer(node2, 9);
IMap<Integer, Integer> map = getMap(node, mapName);
node2.getMap(mapName);
//set test sequencer to subscribers.
int count = 30;
final QueryCache queryCache = map.getQueryCache(queryCacheName, new SqlPredicate("this > 20"), true);
queryCache.addEntryListener(new EventLostListener() {
@Override
public void eventLost(EventLostEvent event) {
queryCache.tryRecover();
}
}, false);
for (int i = 0; i < count; i++) {
map.put(i, i);
}
AssertTask task = new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(9, queryCache.size());
}
};
assertTrueEventually(task);
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class CacheQuorumListenerTest method testQuorumEventProvidesCorrectMemberListSize.
@Test
public void testQuorumEventProvidesCorrectMemberListSize() {
final CountDownLatch belowLatch = new CountDownLatch(1);
Config config = new Config();
QuorumListenerConfig listenerConfig = new QuorumListenerConfig();
listenerConfig.setImplementation(new QuorumListener() {
public void onChange(QuorumEvent quorumEvent) {
if (!quorumEvent.isPresent()) {
Collection<Member> currentMembers = quorumEvent.getCurrentMembers();
assertEquals(3, quorumEvent.getThreshold());
assertTrue(currentMembers.size() < quorumEvent.getThreshold());
belowLatch.countDown();
}
}
});
String cacheName = randomString();
String quorumName = randomString();
QuorumConfig quorumConfig = new QuorumConfig(quorumName, true, 3);
quorumConfig.addListenerConfig(listenerConfig);
config.getCacheConfig(cacheName).setQuorumName(quorumName);
config.addQuorumConfig(quorumConfig);
TestHazelcastInstanceFactory factory = createHazelcastInstanceFactory(3);
HazelcastInstance instance1 = factory.newHazelcastInstance(config);
factory.newHazelcastInstance(config);
HazelcastServerCachingProvider cachingProvider = HazelcastServerCachingProvider.createCachingProvider(instance1);
Cache<Object, Object> cache = cachingProvider.getCacheManager().getCache(cacheName);
try {
cache.put(generateKeyOwnedBy(instance1), 1);
fail("Expected a QuorumException");
} catch (QuorumException expected) {
EmptyStatement.ignore(expected);
}
assertOpenEventually(belowLatch, 15);
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class CacheReadQuorumTest method initialize.
@BeforeClass
public static void initialize() throws Exception {
CacheSimpleConfig cacheConfig = new CacheSimpleConfig();
cacheConfig.setName(CACHE_NAME_PREFIX + "*");
cacheConfig.setQuorumName(QUORUM_ID);
QuorumConfig quorumConfig = new QuorumConfig();
quorumConfig.setName(QUORUM_ID);
quorumConfig.setType(QuorumType.READ);
quorumConfig.setEnabled(true);
quorumConfig.setSize(3);
PartitionedCluster cluster = new PartitionedCluster(new TestHazelcastInstanceFactory()).partitionFiveMembersThreeAndTwo(cacheConfig, quorumConfig);
cachingProvider1 = HazelcastServerCachingProvider.createCachingProvider(cluster.h1);
cachingProvider2 = HazelcastServerCachingProvider.createCachingProvider(cluster.h2);
cachingProvider3 = HazelcastServerCachingProvider.createCachingProvider(cluster.h3);
cachingProvider4 = HazelcastServerCachingProvider.createCachingProvider(cluster.h4);
cachingProvider5 = HazelcastServerCachingProvider.createCachingProvider(cluster.h5);
}
use of com.hazelcast.test.TestHazelcastInstanceFactory in project hazelcast by hazelcast.
the class CacheReadWriteQuorumTest method initialize.
@BeforeClass
public static void initialize() throws Exception {
CacheSimpleConfig cacheConfig = new CacheSimpleConfig();
cacheConfig.setName(CACHE_NAME_PREFIX + "*");
cacheConfig.setQuorumName(QUORUM_ID);
QuorumConfig quorumConfig = new QuorumConfig();
quorumConfig.setName(QUORUM_ID);
quorumConfig.setType(QuorumType.READ_WRITE);
quorumConfig.setEnabled(true);
quorumConfig.setSize(3);
PartitionedCluster cluster = new PartitionedCluster(new TestHazelcastInstanceFactory()).partitionFiveMembersThreeAndTwo(cacheConfig, quorumConfig);
cachingProvider1 = HazelcastServerCachingProvider.createCachingProvider(cluster.h1);
cachingProvider2 = HazelcastServerCachingProvider.createCachingProvider(cluster.h2);
cachingProvider3 = HazelcastServerCachingProvider.createCachingProvider(cluster.h3);
cachingProvider4 = HazelcastServerCachingProvider.createCachingProvider(cluster.h4);
cachingProvider5 = HazelcastServerCachingProvider.createCachingProvider(cluster.h5);
}
Aggregations