use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class TXOrderDUnitTest method testFarSideOpForLoad.
/**
* Tests fix for #40870 Remote CacheListeners invoke afterCreate with Operation.LOCAL_LOAD_CREATE
* when create executed transactionally"
*/
@Ignore("TODO: test is disabled")
@Test
public void testFarSideOpForLoad() throws Exception {
Host host = Host.getHost(0);
VM vm1 = host.getVM(0);
VM vm2 = host.getVM(1);
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
af.setScope(Scope.DISTRIBUTED_ACK);
CacheListener cl1 = new CacheListenerAdapter() {
public void afterCreate(EntryEvent e) {
assertTrue(e.getOperation().isLocalLoad());
}
};
af.addCacheListener(cl1);
CacheLoader cl = new CacheLoader() {
public Object load(LoaderHelper helper) throws CacheLoaderException {
LogWriterUtils.getLogWriter().info("Loading value:" + helper.getKey() + "_value");
return helper.getKey() + "_value";
}
public void close() {
}
};
af.setCacheLoader(cl);
createRootRegion("r1", af.create());
return null;
}
});
vm2.invoke(new SerializableCallable() {
public Object call() throws Exception {
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
af.setScope(Scope.DISTRIBUTED_ACK);
CacheListener cl1 = new CacheListenerAdapter() {
public void afterCreate(EntryEvent e) {
LogWriterUtils.getLogWriter().info("op:" + e.getOperation().toString());
assertTrue(!e.getOperation().isLocalLoad());
}
};
af.addCacheListener(cl1);
createRootRegion("r1", af.create());
return null;
}
});
vm1.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region r = getRootRegion("r1");
getCache().getCacheTransactionManager().begin();
r.get("obj_2");
getCache().getCacheTransactionManager().commit();
return null;
}
});
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class TXOrderDUnitTest method testFarSideOrder.
/**
* make sure listeners get invoked in correct order on far side of tx
*/
@Test
public void testFarSideOrder() throws CacheException {
initOtherId();
AttributesFactory af = new AttributesFactory();
af.setDataPolicy(DataPolicy.REPLICATE);
af.setScope(Scope.DISTRIBUTED_ACK);
CacheListener cl1 = new CacheListenerAdapter() {
public void afterCreate(EntryEvent e) {
assertEquals(getCurrentExpectedKey(), e.getKey());
}
};
af.addCacheListener(cl1);
Region r1 = createRootRegion("r1", af.create());
Region r2 = r1.createSubregion("r2", af.create());
r2.createSubregion("r3", af.create());
TransactionListener tl1 = new TransactionListenerAdapter() {
public void afterCommit(TransactionEvent e) {
assertEquals(6, e.getEvents().size());
ArrayList keys = new ArrayList();
Iterator it = e.getEvents().iterator();
while (it.hasNext()) {
EntryEvent ee = (EntryEvent) it.next();
keys.add(ee.getKey());
assertEquals(null, ee.getCallbackArgument());
assertEquals(true, ee.isCallbackArgumentAvailable());
}
assertEquals(TXOrderDUnitTest.this.expectedKeys, keys);
TXOrderDUnitTest.this.invokeCount = 1;
}
};
CacheTransactionManager ctm = getCache().getCacheTransactionManager();
ctm.addListener(tl1);
this.invokeCount = 0;
this.clCount = 0;
this.expectedKeys = Arrays.asList(new String[] { "b", "c", "a", "a2", "c2", "b2" });
doCommitOtherVm();
assertEquals(1, this.invokeCount);
assertEquals(6, this.clCount);
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class MultiVMRegionTestCase method testOrderedUpdates.
/**
* Tests that distributed updates are delivered in order
*
* <P>
*
* Note that this test does not make sense for regions that are {@link Scope#DISTRIBUTED_NO_ACK}
* for which we do not guarantee the ordering of updates for a single producer/single consumer.
*
* DISABLED 4-16-04 - the current implementation assumes events are processed synchronously, which
* is no longer true.
*/
@Ignore("TODO: test is DISABLED 4-16-04 - the current implementation assumes events are processed synchronously, which is no longer true")
@Test
public void testOrderedUpdates() throws Exception {
assumeFalse(getRegionAttributes().getScope() == Scope.DISTRIBUTED_NO_ACK);
final String name = this.getUniqueName();
final Object key = "KEY";
final int lastNumber = 10;
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
SerializableRunnable create = new CacheSerializableRunnable("Create region entry") {
@Override
public void run2() throws CacheException {
Region region = createRegion(name);
region.create(key, null);
}
};
vm0.invoke(create);
vm1.invoke(create);
vm1.invoke(new CacheSerializableRunnable("Set listener") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.setUserAttribute(new LinkedBlockingQueue());
region.getAttributesMutator().addCacheListener(new CacheListenerAdapter() {
@Override
public void afterUpdate(EntryEvent e) {
Region region2 = e.getRegion();
LinkedBlockingQueue queue = (LinkedBlockingQueue) region2.getUserAttribute();
Object value = e.getNewValue();
assertNotNull(value);
try {
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("++ Adding " + value);
queue.put(value);
} catch (InterruptedException ex) {
fail("Why was I interrupted?", ex);
}
}
});
flushIfNecessary(region);
}
});
AsyncInvocation ai1 = vm1.invokeAsync(new CacheSerializableRunnable("Verify") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
LinkedBlockingQueue queue = (LinkedBlockingQueue) region.getUserAttribute();
for (int i = 0; i <= lastNumber; i++) {
try {
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("++ Waiting for " + i);
Integer value = (Integer) queue.take();
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("++ Got " + value);
assertEquals(i, value.intValue());
} catch (InterruptedException ex) {
fail("Why was I interrupted?", ex);
}
}
}
});
AsyncInvocation ai0 = vm0.invokeAsync(new CacheSerializableRunnable("Populate") {
@Override
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i <= lastNumber; i++) {
// org.apache.geode.internal.GemFireVersion.waitForJavaDebugger(getLogWriter());
region.put(key, new Integer(i));
}
}
});
ThreadUtils.join(ai0, 30 * 1000);
ThreadUtils.join(ai1, 30 * 1000);
if (ai0.exceptionOccurred()) {
fail("ai0 failed", ai0.getException());
} else if (ai1.exceptionOccurred()) {
fail("ai1 failed", ai1.getException());
}
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class PostProcessorDUnitTest method testRegisterInterestPostProcess.
@Test
public void testRegisterInterestPostProcess() {
client1.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
ClientRegionFactory factory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
factory.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterUpdate(EntryEvent event) {
assertEquals("super-user/AuthRegion/key1/value2", event.getSerializedNewValue().getDeserializedValue());
}
});
Region region = factory.create(REGION_NAME);
region.put("key1", "value1");
region.registerInterest("key1");
});
client2.invoke(() -> {
ClientCache cache = createClientCache("dataUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
region.put("key1", "value2");
});
}
use of org.apache.geode.cache.util.CacheListenerAdapter in project geode by apache.
the class PDXPostProcessorDUnitTest method testRegisterInterest.
@Test
public void testRegisterInterest() {
IgnoredException.addIgnoredException("NoAvailableServersException");
client1.invoke(() -> {
ClientCache cache = createClientCache("super-user", "1234567", server.getPort());
ClientRegionFactory factory = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
factory.addCacheListener(new CacheListenerAdapter() {
@Override
public void afterUpdate(EntryEvent event) {
Object key = event.getKey();
Object value = ((EntryEventImpl) event).getDeserializedValue();
if (key.equals("key1")) {
assertTrue(value instanceof SimpleClass);
} else if (key.equals("key2")) {
assertTrue(Arrays.equals(BYTES, (byte[]) value));
}
}
});
Region region = factory.create(REGION_NAME);
region.put("key1", "value1");
region.registerInterest("key1");
region.registerInterest("key2");
});
client2.invoke(() -> {
ClientCache cache = createClientCache("dataUser", "1234567", server.getPort());
Region region = createProxyRegion(cache, REGION_NAME);
// put in a value that's a domain object
region.put("key1", new SimpleClass(1, (byte) 1));
region.put("key2", BYTES);
});
// wait for events to fire
Awaitility.await().atMost(1, TimeUnit.SECONDS);
PDXPostProcessor pp = (PDXPostProcessor) SecurityService.getSecurityService().getPostProcessor();
assertEquals(pp.getCount(), 2);
}
Aggregations