use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class ConcurrentMapOpsDUnitTest method doRetriedOperation.
private void doRetriedOperation(final Operation op, boolean usePR) {
Host host = Host.getHost(0);
final VM server1 = host.getVM(0);
final VM server2 = host.getVM(1);
final VM client = host.getVM(2);
final int port1 = createRegionsAndStartServer(server1, true);
final int port2 = createRegionsAndStartServer(server2, true);
final String regionName = usePR ? PR_REG_NAME : REP_REG_NAME;
IgnoredException.addIgnoredException("java.net.SocketException");
createClientRegion(client, port1, false, port2);
SerializableCallable getID = new SerializableCallable("get DM ID") {
public Object call() {
return getSystem().getDistributedMember();
}
};
final DistributedMember server1ID = (DistributedMember) server1.invoke(getID);
final DistributedMember server2ID = (DistributedMember) server2.invoke(getID);
Set<IgnoredException> exceptions = new HashSet<IgnoredException>();
exceptions.add(IgnoredException.addIgnoredException("Membership: requesting removal", server1));
exceptions.add(IgnoredException.addIgnoredException("Membership: requesting removal", server2));
exceptions.add(IgnoredException.addIgnoredException("ForcedDisconnect", server1));
exceptions.add(IgnoredException.addIgnoredException("ForcedDisconnect", server2));
try {
server1.invoke(new SerializableCallable("install crasher in server1") {
public Object call() throws Exception {
Region r = getCache().getRegion(regionName);
r.put("key0", "value");
if (op == Operation.PUT_IF_ABSENT) {
r.destroy("key0");
}
// force client to use server1 for now
// getCache().getCacheServers().get(0).stop();
r.getAttributesMutator().addCacheListener(new CacheListenerAdapter() {
private void killSender(EntryEvent event) {
if (event.isOriginRemote()) {
MembershipManager mgr = MembershipManagerHelper.getMembershipManager(getSystem());
mgr.requestMemberRemoval(server2ID, "removing for test");
try {
mgr.waitForDeparture(server2ID);
} catch (Exception e) {
fail("failed to stop the other server for this test:" + e.getMessage());
}
}
}
@Override
public void afterCreate(EntryEvent event) {
getCache().getLogger().info("afterCreate invoked with " + event);
killSender(event);
}
@Override
public void afterUpdate(EntryEvent event) {
getCache().getLogger().info("afterUpdate invoked with " + event);
killSender(event);
}
@Override
public void afterDestroy(EntryEvent event) {
getCache().getLogger().info("afterDestroy invoked with " + event);
killSender(event);
}
});
return null;
}
});
server2.invoke(new SerializableCallable("install crasher in server2") {
public Object call() throws Exception {
Region r = getCache().getRegion(regionName);
// force client to use server1 for now
// getCache().getCacheServers().get(0).stop();
r.getAttributesMutator().addCacheListener(new CacheListenerAdapter() {
private void killSender(EntryEvent event) {
if (event.isOriginRemote()) {
MembershipManager mgr = MembershipManagerHelper.getMembershipManager(getSystem());
mgr.requestMemberRemoval(server1ID, "removing for test");
try {
mgr.waitForDeparture(server1ID);
} catch (Exception e) {
fail("failed to stop the other server for this test:" + e.getMessage());
}
}
}
@Override
public void afterCreate(EntryEvent event) {
getCache().getLogger().info("afterCreate invoked with " + event);
killSender(event);
}
@Override
public void afterUpdate(EntryEvent event) {
getCache().getLogger().info("afterUpdate invoked with " + event);
killSender(event);
}
@Override
public void afterDestroy(EntryEvent event) {
getCache().getLogger().info("afterDestroy invoked with " + event);
killSender(event);
}
});
return null;
}
});
client.invoke(new SerializableRunnable() {
public void run() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
Region r = cache.getRegion(regionName);
if (op == Operation.PUT_IF_ABSENT) {
assertTrue("expected putIfAbsent to succeed and return null", r.putIfAbsent("key0", "newvalue") == null);
} else if (op == Operation.REMOVE) {
assertTrue("expected remove operation to succeed and return true", r.remove("key0", "value"));
} else if (op == Operation.REPLACE) {
assertTrue("expected replace operation to succeed and return true", r.replace("key0", "value", "newvalue"));
}
}
});
} finally {
disconnectAllFromDS();
for (IgnoredException ex : exceptions) {
ex.remove();
}
}
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class DeltaPropagationStatsDUnitTest method createClientCache.
public static void createClientCache(String host, Integer port) throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
cache = new DeltaPropagationStatsDUnitTest().createCache(props);
pool = PoolManager.createFactory().addServer(host, port).setThreadLocalConnections(true).setMinConnections(1).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setReadTimeout(10000).setSocketBufferSize(32768).create("DeltaPropagationStatsDunitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.NORMAL);
factory.setPoolName(pool.getName());
factory.setCloningEnabled(false);
factory.addCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
if (LAST_KEY.equals(event.getKey())) {
lastKeyReceived = true;
}
}
});
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs).registerInterest("ALL_KEYS");
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class ConflationDUnitTest method createClientCache2UniqueWriter.
/**
* create client 2 with 2 regions each with a unique writer but both having a common listener
*
* @throws Exception
*/
public static void createClientCache2UniqueWriter(String host, Integer port) throws Exception {
ConflationDUnitTest test = new ConflationDUnitTest();
cache = test.createCache(createProperties1());
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName(createPool(host, "p1", port, true).getName());
factory.addCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
String val = (String) event.getNewValue();
LogWriterUtils.getLogWriter().info("Listener received event " + event);
synchronized (ConflationDUnitTest.class) {
if (val.equals(MARKER)) {
count++;
} else {
counterCreate++;
}
if (2 == count) {
ConflationDUnitTest.class.notify();
}
}
}
public void afterUpdate(EntryEvent event) {
synchronized (this) {
counterUpdate++;
}
}
public void afterDestroy(EntryEvent event) {
synchronized (this) {
if (!event.getKey().equals(MARKER)) {
counterDestroy++;
}
}
}
});
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME1, attrs);
factory.setPoolName(createPool(host, "p2", port, true).getName());
attrs = factory.create();
cache.createRegion(REGION_NAME2, attrs);
}
use of org.apache.geode.cache.EntryEvent in project geode by apache.
the class ConflationDUnitTest method createClientCache2CommonWriterTest3.
public static void createClientCache2CommonWriterTest3(String host, Integer port) throws Exception {
ConflationDUnitTest test = new ConflationDUnitTest();
cache = test.createCache(createProperties1());
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setPoolName(createPool(host, "p1", port, true).getName());
factory.addCacheListener(new CacheListenerAdapter() {
public void afterCreate(EntryEvent event) {
LogWriterUtils.getLogWriter().info("Listener received event " + event);
String val = (String) event.getNewValue();
synchronized (ConflationDUnitTest.class) {
if (val.equals(MARKER)) {
count++;
} else {
counterCreate++;
}
if (2 == count) {
ConflationDUnitTest.class.notify();
}
}
}
public void afterUpdate(EntryEvent event) {
LogWriterUtils.getLogWriter().info("Listener received event " + event);
synchronized (this) {
counterUpdate++;
}
}
public void afterDestroy(EntryEvent event) {
LogWriterUtils.getLogWriter().info("Listener received event " + event);
synchronized (this) {
if (!event.getKey().equals(MARKER)) {
counterDestroy++;
}
}
}
});
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME1, attrs);
cache.createRegion(REGION_NAME2, attrs);
}
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();
}
Aggregations