use of com.hazelcast.internal.nearcache.impl.invalidation.Invalidation in project hazelcast by hazelcast.
the class CacheDestroyTest method testInvalidationListenerCallCount.
@Test
public void testInvalidationListenerCallCount() {
final ICache<String, String> cache = createCache();
final AtomicInteger counter = new AtomicInteger(0);
final CacheConfig config = cache.getConfiguration(CacheConfig.class);
registerInvalidationListener(new CacheEventListener() {
@Override
public void handleEvent(Object eventObject) {
if (eventObject instanceof Invalidation) {
Invalidation event = (Invalidation) eventObject;
if (null == event.getKey() && config.getNameWithPrefix().equals(event.getName())) {
counter.incrementAndGet();
}
}
}
}, config.getNameWithPrefix());
cache.destroy();
// Make sure that at least 1 invalidation event has been received
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(counter.get() >= 1);
}
}, 2);
// Make sure that no more than INSTNACE_COUNT events are received ever
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(counter.get() <= INSTANCE_COUNT);
}
}, 3);
}
use of com.hazelcast.internal.nearcache.impl.invalidation.Invalidation in project hazelcast by hazelcast.
the class CacheClearTest method testInvalidationListenerCallCount.
@Test
public void testInvalidationListenerCallCount() {
final ICache<String, String> cache = createCache();
Map<String, String> entries = createAndFillEntries();
for (Map.Entry<String, String> entry : entries.entrySet()) {
cache.put(entry.getKey(), entry.getValue());
}
// Verify that put works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String expectedValue = entries.get(key);
String actualValue = cache.get(key);
assertEquals(expectedValue, actualValue);
}
final AtomicInteger counter = new AtomicInteger(0);
final CacheConfig config = cache.getConfiguration(CacheConfig.class);
registerInvalidationListener(eventObject -> {
if (eventObject instanceof Invalidation) {
Invalidation event = (Invalidation) eventObject;
if (null == event.getKey() && config.getNameWithPrefix().equals(event.getName())) {
counter.incrementAndGet();
}
}
}, config.getNameWithPrefix());
cache.clear();
// Make sure that one event is received
assertTrueEventually(() -> assertEquals(1, counter.get()), 5);
// Make sure that the callback is not called for a while
assertTrueAllTheTime(() -> assertTrue(counter.get() <= 1), 3);
}
use of com.hazelcast.internal.nearcache.impl.invalidation.Invalidation in project hazelcast by hazelcast.
the class InvalidationTest method setUp.
@Before
public void setUp() {
Config config = getBaseConfig();
HazelcastInstance hz = createHazelcastInstance(config);
serializationService = getSerializationService(hz);
Data key = serializationService.toData("key");
String mapName = "mapName";
UUID sourceUuid = UUID.randomUUID();
UUID partitionUuid = UUID.randomUUID();
singleInvalidation = new SingleNearCacheInvalidation(key, mapName, sourceUuid, partitionUuid, 1);
List<Invalidation> invalidations = Collections.singletonList(singleInvalidation);
batchInvalidation = new BatchNearCacheInvalidation(mapName, invalidations);
}
use of com.hazelcast.internal.nearcache.impl.invalidation.Invalidation in project hazelcast by hazelcast.
the class BatchNearCacheInvalidationTest method equals_itself_after_deserialization.
@Test
public void equals_itself_after_deserialization() throws Exception {
Data key = ss.toData("key");
String mapName = "mapName";
String sourceUuid = "sourceUuid";
UUID partitionUuid = UUID.randomUUID();
List<Invalidation> invalidations = new ArrayList<Invalidation>();
invalidations.add(new SingleNearCacheInvalidation(key, mapName, sourceUuid, partitionUuid, 1));
BatchNearCacheInvalidation batch = new BatchNearCacheInvalidation(mapName, invalidations);
Data data = ss.toData(batch);
Object object = ss.toObject(data);
assertInstanceOf(BatchNearCacheInvalidation.class, object);
List<Invalidation> actualInvalidations = ((BatchNearCacheInvalidation) object).getInvalidations();
assertDeserializedEqualsExpected(key, mapName, partitionUuid, actualInvalidations);
}
use of com.hazelcast.internal.nearcache.impl.invalidation.Invalidation in project hazelcast by hazelcast.
the class BatchNearCacheInvalidationTest method assertDeserializedEqualsExpected.
private void assertDeserializedEqualsExpected(Data key, String mapName, UUID partitionUuid, List<Invalidation> invalidations) {
for (Invalidation invalidation : invalidations) {
Data invalidationKey = invalidation.getKey();
assertTrue(invalidationKey.equals(key));
assertEquals(mapName, invalidation.getName());
assertEquals(partitionUuid, invalidation.getPartitionUuid());
}
}
Aggregations