use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class ExportLogsCacheWriterUnitTest method writerReturnsPathIfWritten.
@Test
public void writerReturnsPathIfWritten() throws Exception {
writer.startFile("server-1");
EntryEvent event = mock(EntryEvent.class);
when(event.getNewValue()).thenReturn(new byte[] {});
writer.beforeCreate(event);
assertThat(writer.endFile()).isNotNull();
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class ClientToServerDeltaDUnitTest method createClientCache.
/*
* create client cache
*/
public static void createClientCache(String host, Integer port, Boolean attachListener, Boolean isEmpty, Boolean isCq, String[] cqQueryString, Boolean registerInterestAll, Boolean enableSubscription) throws Exception {
updates = 0;
create = 0;
firstUpdate = null;
secondUpdate = null;
error = false;
lastKeyReceived = false;
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new ClientToServerDeltaDUnitTest().createCache(props);
pool = (PoolImpl) PoolManager.createFactory().addServer(host, port.intValue()).setThreadLocalConnections(true).setMinConnections(2).setSubscriptionEnabled(enableSubscription).setSubscriptionRedundancy(0).setReadTimeout(10000).setPingInterval(1000).setSocketBufferSize(32768).create("ClientToServerDeltaDunitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setConcurrencyChecksEnabled(true);
if (isEmpty) {
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
factory.setDataPolicy(DataPolicy.EMPTY);
} else {
factory.setDataPolicy(DataPolicy.NORMAL);
}
factory.setPoolName(pool.getName());
factory.setCloningEnabled(false);
// region with empty data policy
RegionAttributes attrs = factory.create();
region = cache.createRegion(REGION_NAME, attrs);
if (attachListener) {
region.getAttributesMutator().addCacheListener(new CacheListenerAdapter() {
@Override
public void afterCreate(EntryEvent event) {
create++;
if (LAST_KEY.equals(event.getKey())) {
lastKeyReceived = true;
}
;
}
@Override
public void afterUpdate(EntryEvent event) {
switch(updates) {
case 0:
// first delta
validateUpdates(event, firstUpdate, "FIRST");
updates++;
break;
case 1:
// combine delta
validateUpdates(event, firstUpdate, "FIRST");
validateUpdates(event, secondUpdate, "SECOND");
updates++;
break;
default:
break;
}
}
});
}
if (registerInterestAll) {
region.registerInterest("ALL_KEYS");
}
if (isCq) {
CqAttributesFactory cqf = new CqAttributesFactory();
CqListenerAdapter cqlist = new CqListenerAdapter() {
@Override
public void onEvent(CqEvent cqEvent) {
Object key = cqEvent.getKey();
if (LAST_KEY.equals(key)) {
lastKeyReceived = true;
}
logger.fine("CQ event received for (key, value): (" + key + ", " + cqEvent.getNewValue() + ")");
}
@Override
public void onError(CqEvent cqEvent) {
logger.fine("CQ error received for key: " + cqEvent.getKey());
}
};
cqf.addCqListener(cqlist);
CqAttributes cqa = cqf.create();
for (int i = 0; i < cqQueryString.length; i++) {
CqQuery cq = cache.getQueryService().newCq("Delta_Query_" + i, cqQueryString[i], cqa);
cq.execute();
}
}
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class P2PDeltaPropagationDUnitTest method createServerCache.
public static void createServerCache(Boolean flag, DataPolicy policy, Scope scope, Boolean listener, Boolean interestPolicyAll, Integer port) throws Exception {
P2PDeltaPropagationDUnitTest test = new P2PDeltaPropagationDUnitTest();
Properties props = new Properties();
if (!flag) {
props.setProperty(DELTA_PROPAGATION, "false");
}
cache = test.createCache(props);
AttributesFactory factory = new AttributesFactory();
factory.setScope(scope);
factory.setDataPolicy(policy);
if (policy == DataPolicy.EMPTY && interestPolicyAll) {
factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
}
if (listener) {
factory.addCacheListener(new CacheListenerAdapter() {
@SuppressWarnings("synthetic-access")
public void afterUpdate(EntryEvent event) {
numOfUpdates++;
cache.getLoggerI18n().fine("afterUpdate(): numOfUpdates = " + numOfUpdates);
cache.getLoggerI18n().fine("(key, val): " + event.getKey() + ", " + event.getNewValue());
if (event.getOldValue() != null) {
if (event.getOldValue() == event.getNewValue()) {
check = Boolean.TRUE;
}
}
if (((EntryEventImpl) event).getDeltaBytes() != null) {
cache.getLoggerI18n().fine("delta bytes received. " + hasDeltaBytes);
assertTrue("No full value received for event " + event, ((EntryEventImpl) event).getNewValue() != null);
hasDeltaBytes++;
} else {
cache.getLoggerI18n().fine("delta bytes not received.");
}
}
});
}
Region region = cache.createRegion(REGION_NAME, factory.create());
if (!policy.isReplicate()) {
region.create("KEY", "KEY");
}
if (port != null) {
CacheServer server1 = cache.addCacheServer();
server1.setPort(port);
server1.start();
}
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class HARegionJUnitTest method testEventIdSetForEvictDestroy.
/**
* Test to verify event id exists when evict destroy happens.
*/
@Test
public void testEventIdSetForEvictDestroy() throws Exception {
AttributesFactory factory = new AttributesFactory();
factory.setCacheListener(new CacheListenerAdapter() {
public void afterDestroy(EntryEvent event) {
assertTrue("eventId has not been set for " + event, ((EntryEventImpl) event).getEventId() != null);
}
});
EvictionAttributes evAttr = EvictionAttributes.createLRUEntryAttributes(1, EvictionAction.LOCAL_DESTROY);
factory.setEvictionAttributes(evAttr);
RegionAttributes attrs = factory.createRegionAttributes();
Region region = cache.createVMRegion("TEST_REGION", attrs);
region.put("key1", "value1");
region.put("key2", "value2");
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class HARQueueNewImplDUnitTest method createClientCache.
public static void createClientCache(String host, Integer port1, Integer port2, String rLevel, Boolean addListener) throws Exception {
CacheServerTestUtil.disableShufflingOfEndpoints();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new HARQueueNewImplDUnitTest().createCache(props);
AttributesFactory factory = new AttributesFactory();
ClientServerTestCase.configureConnectionPool(factory, host, port1.intValue(), port2.intValue(), true, Integer.parseInt(rLevel), 2, null, 1000, 250, false);
factory.setScope(Scope.LOCAL);
if (addListener.booleanValue()) {
factory.addCacheListener(new CacheListenerAdapter() {
public void afterInvalidate(EntryEvent event) {
logger.fine("Invalidate Event: <" + event.getKey() + ", " + event.getNewValue() + ">");
numOfInvalidates++;
}
public void afterCreate(EntryEvent event) {
logger.fine("Create Event: <" + event.getKey() + ", " + event.getNewValue() + ">");
numOfCreates++;
}
public void afterUpdate(EntryEvent event) {
logger.fine("Update Event: <" + event.getKey() + ", " + event.getNewValue() + ">");
numOfUpdates++;
}
});
}
RegionAttributes attrs = factory.create();
cache.createRegion(regionName, attrs);
logger = cache.getLogger();
}
Aggregations