use of org.apache.geode.cache30.TestCacheWriter in project geode by apache.
the class ConnectionPoolDUnitTest method testDestroyRegion.
/**
* Tests that a {@link Region#localDestroyRegion} is not propagated to the server and that a
* {@link Region#destroyRegion} is. Also makes sure that callback arguments are passed correctly.
*/
@Ignore("TODO")
@Test
public void testDestroyRegion() throws CacheException {
final String name = this.getName();
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final Object callbackArg = "DESTROY CALLBACK";
vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
CacheWriter cw = new TestCacheWriter() {
public void beforeCreate2(EntryEvent event) throws CacheWriterException {
}
public void beforeRegionDestroy2(RegionEvent event) throws CacheWriterException {
assertEquals(callbackArg, event.getCallbackArgument());
}
};
AttributesFactory factory = getBridgeServerRegionAttributes(null, cw);
createRegion(name, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
});
final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
SerializableRunnable create = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(factory, host0, port, -1, true, -1, -1, null);
createRegion(name, factory.create());
}
};
vm1.invoke(create);
vm2.invoke(create);
vm1.invoke(new CacheSerializableRunnable("Local destroy region") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.localDestroyRegion();
assertNull(getRootRegion().getSubregion(name));
// close the bridge writer to prevent callbacks on the connections
// Not necessary since locally destroying the region takes care of this.
// getPoolClient(region).close();
}
});
vm2.invoke(new CacheSerializableRunnable("No destroy propagate") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
assertNotNull(region);
}
});
vm0.invoke(new CacheSerializableRunnable("Check no server cache writer") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
TestCacheWriter writer = getTestWriter(region);
writer.wasInvoked();
}
});
vm1.invoke(create);
vm1.invoke(new CacheSerializableRunnable("Distributed destroy region") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
assertNotNull(region);
region.destroyRegion(callbackArg);
assertNull(getRootRegion().getSubregion(name));
// close the bridge writer to prevent callbacks on the connections
// Not necessary since locally destroying the region takes care of this.
// getPoolClient(region).close();
}
});
// Wait for destroys to propagate
Wait.pause(1000);
vm2.invoke(new CacheSerializableRunnable("Verify destroy propagate") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
assertNull(region);
// todo close the bridge writer
// Not necessary since locally destroying the region takes care of this.
}
});
vm0.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
use of org.apache.geode.cache30.TestCacheWriter in project geode by apache.
the class ConnectionPoolDUnitTest method test001CallbackArg.
/**
* Tests that the callback argument is sent to the server
*/
@Test
public void test001CallbackArg() throws CacheException {
final String name = this.getName();
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final Object createCallbackArg = "CREATE CALLBACK ARG";
final Object updateCallbackArg = "PUT CALLBACK ARG";
vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
CacheWriter cw = new TestCacheWriter() {
public final void beforeUpdate2(EntryEvent event) throws CacheWriterException {
Object beca = event.getCallbackArgument();
assertEquals(updateCallbackArg, beca);
}
public void beforeCreate2(EntryEvent event) throws CacheWriterException {
Object beca = event.getCallbackArgument();
assertEquals(createCallbackArg, beca);
}
};
AttributesFactory factory = getBridgeServerRegionAttributes(null, cw);
createRegion(name, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
});
final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
SerializableRunnable create = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(factory, NetworkUtils.getServerHostName(host), port, -1, true, -1, -1, null);
createRegion(name, factory.create());
}
};
vm1.invoke(create);
vm1.invoke(new CacheSerializableRunnable("Add entries") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
region.create(new Integer(i), "old" + i, createCallbackArg);
}
for (int i = 0; i < 10; i++) {
region.put(new Integer(i), "new" + i, updateCallbackArg);
}
}
});
vm0.invoke(new CacheSerializableRunnable("Check cache writer") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
TestCacheWriter writer = getTestWriter(region);
assertTrue(writer.wasInvoked());
}
});
SerializableRunnable close = new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.localDestroyRegion();
}
};
vm1.invoke(close);
vm0.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
use of org.apache.geode.cache30.TestCacheWriter in project geode by apache.
the class ConnectionPoolDUnitTest method test025Destroy.
/**
* Tests that a {@link Region#localDestroy} is not propagated to the server and that a
* {@link Region#destroy} is. Also makes sure that callback arguments are passed correctly.
*/
@Test
public void test025Destroy() throws CacheException {
final String name = this.getName();
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final Object callbackArg = "DESTROY CALLBACK";
vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
CacheWriter cw = new TestCacheWriter() {
public void beforeCreate2(EntryEvent event) throws CacheWriterException {
}
public void beforeDestroy2(EntryEvent event) throws CacheWriterException {
Object beca = event.getCallbackArgument();
assertEquals(callbackArg, beca);
}
};
AttributesFactory factory = getBridgeServerRegionAttributes(null, cw);
createRegion(name, factory.create());
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
});
final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
SerializableRunnable create = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(factory, host0, port, -1, true, -1, -1, null);
Region rgn = createRegion(name, factory.create());
rgn.registerInterestRegex(".*", false, false);
}
};
vm1.invoke(create);
vm1.invoke(new CacheSerializableRunnable("Populate region") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
region.put(new Integer(i), String.valueOf(i));
}
}
});
vm2.invoke(create);
vm2.invoke(new CacheSerializableRunnable("Load region") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
assertEquals(String.valueOf(i), region.get(new Integer(i)));
}
}
});
vm1.invoke(new CacheSerializableRunnable("Local destroy") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
region.localDestroy(new Integer(i));
}
}
});
vm2.invoke(new CacheSerializableRunnable("No destroy propagate") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
assertEquals(String.valueOf(i), region.get(new Integer(i)));
}
}
});
vm1.invoke(new CacheSerializableRunnable("Fetch from server") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
assertEquals(String.valueOf(i), region.get(new Integer(i)));
}
}
});
vm0.invoke(new CacheSerializableRunnable("Check no server cache writer") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
TestCacheWriter writer = getTestWriter(region);
writer.wasInvoked();
}
});
vm1.invoke(new CacheSerializableRunnable("Distributed destroy") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
region.destroy(new Integer(i), callbackArg);
}
}
});
// Wait for destroys to propagate
Wait.pause(1000);
vm1.invoke(new CacheSerializableRunnable("Attempt get from server") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
assertNull(region.getEntry(new Integer(i)));
}
}
});
vm2.invoke(new CacheSerializableRunnable("Validate destroy propagate") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
assertNull(region.getEntry(new Integer(i)));
}
}
});
SerializableRunnable close = new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.localDestroyRegion();
}
};
vm1.invoke(close);
vm2.invoke(close);
vm0.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
use of org.apache.geode.cache30.TestCacheWriter in project geode by apache.
the class ConnectionPoolDUnitTest method test002CallbackArg2.
/**
* Tests that consecutive puts have the callback assigned appropriately.
*/
@Test
public void test002CallbackArg2() throws CacheException {
final String name = this.getName();
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
final Object createCallbackArg = "CREATE CALLBACK ARG";
// final Object updateCallbackArg = "PUT CALLBACK ARG";
vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
CacheWriter cw = new TestCacheWriter() {
public void beforeCreate2(EntryEvent event) throws CacheWriterException {
Integer key = (Integer) event.getKey();
if (key.intValue() % 2 == 0) {
Object beca = event.getCallbackArgument();
assertEquals(createCallbackArg, beca);
} else {
Object beca = event.getCallbackArgument();
assertNull(beca);
}
}
};
AttributesFactory factory = getBridgeServerRegionAttributes(null, cw);
createRegion(name, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
});
final int port = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
SerializableRunnable create = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
getLonerSystem();
getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(false);
ClientServerTestCase.configureConnectionPool(factory, host0, port, -1, true, -1, -1, null);
createRegion(name, factory.create());
}
};
vm1.invoke(create);
vm1.invoke(new CacheSerializableRunnable("Add entries") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
for (int i = 0; i < 10; i++) {
if (i % 2 == 0) {
region.create(new Integer(i), "old" + i, createCallbackArg);
} else {
region.create(new Integer(i), "old" + i);
}
}
}
});
SerializableRunnable close = new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.localDestroyRegion();
}
};
vm1.invoke(close);
vm0.invoke(new CacheSerializableRunnable("Check cache writer") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
TestCacheWriter writer = getTestWriter(region);
assertTrue(writer.wasInvoked());
}
});
vm0.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
Aggregations