use of org.apache.geode.cache30.CacheSerializableRunnable 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.CacheSerializableRunnable in project geode by apache.
the class ConnectionPoolDUnitTest method test033NotSerializableException.
// this test doesn't do anything so I commented it out
// /**
// * Tests that new connections update client notification connections.
// */
// public void test032NewConnections() throws Exception {
// 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);
// // Cache server serves up the region
// vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {
// public void run2() throws CacheException {
// AttributesFactory factory = getBridgeServerRegionAttributes(null,null);
// Region region = createRegion(name, factory.create());
// pause(1000);
// try {
// startBridgeServer(0);
// } catch (Exception ex) {
// fail("While starting CacheServer", ex);
// }
// }
// });
// final int port =
// vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
// final String host0 = getServerHostName(vm0.getHost());
// SerializableRunnable create =
// new CacheSerializableRunnable("Create region") {
// public void run2() throws CacheException {
// getCache();
// AttributesFactory factory = new AttributesFactory();
// factory.setScope(Scope.LOCAL);
// ClientServerTestCase.configureConnectionPool(factory,host0,port,-1,true,-1,-1, null);
// createRegion(name, factory.create());
// }
// };
// vm1.invoke(create);
// vm2.invoke(create);
// vm1.invoke(new CacheSerializableRunnable("Create new connection") {
// public void run2() throws CacheException {
// Region region = getRootRegion().getSubregion(name);
// BridgeClient writer = getPoolClient(region);
// Endpoint[] endpoints = (Endpoint[])writer.getEndpoints();
// for (int i=0; i<endpoints.length; i++) endpoints[i].addNewConnection();
// }
// });
// 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());
// }
// });
// }
/**
* Tests that creating, putting and getting a non-serializable key or value throws the correct
* (NotSerializableException) exception.
*/
@Test
public void test033NotSerializableException() 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);
vm0.invoke(new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
AttributesFactory factory = getBridgeServerRegionAttributes(null, null);
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("Attempt to create a non-serializable value") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
try {
region.create(new Integer(1), new ConnectionPoolTestNonSerializable());
fail("Should not have been able to create a ConnectionPoolTestNonSerializable");
} catch (Exception e) {
if (!(e.getCause() instanceof java.io.NotSerializableException))
fail("Unexpected exception while creating a non-serializable value " + e);
}
}
});
vm1.invoke(new CacheSerializableRunnable("Attempt to put a non-serializable value") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
try {
region.put(new Integer(1), new ConnectionPoolTestNonSerializable());
fail("Should not have been able to put a ConnectionPoolTestNonSerializable");
} catch (Exception e) {
if (!(e.getCause() instanceof java.io.NotSerializableException))
fail("Unexpected exception while putting a non-serializable value " + e);
}
}
});
vm1.invoke(new CacheSerializableRunnable("Attempt to get a non-serializable key") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
try {
region.get(new ConnectionPoolTestNonSerializable());
fail("Should not have been able to get a ConnectionPoolTestNonSerializable");
} catch (Exception e) {
if (!(e.getCause() instanceof java.io.NotSerializableException))
fail("Unexpected exception while getting a non-serializable key " + e);
}
}
});
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.CacheSerializableRunnable in project geode by apache.
the class ConnectionPoolDUnitTest method basicTestBridgeServerFailover.
private void basicTestBridgeServerFailover(final int cnxCount) 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);
// Create two bridge servers
SerializableRunnable createCacheServer = new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
AttributesFactory factory = getBridgeServerRegionAttributes(null, null);
createRegion(name, factory.create());
// pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
};
vm0.invoke(createCacheServer);
vm1.invoke(createCacheServer);
final int port0 = vm0.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(vm0.getHost());
final int port1 = vm1.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
// final String host1 = getServerHostName(vm1.getHost());
// Create one bridge client in this VM
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, port0, port1, true, -1, cnxCount, null, 100);
Region region = createRegion(name, factory.create());
// force connections to form
region.put("keyInit", new Integer(0));
region.put("keyInit2", new Integer(0));
}
};
vm2.invoke(create);
// Launch async thread that puts objects into cache. This thread will execute until
// the test has ended (which is why the RegionDestroyedException and CacheClosedException
// are caught and ignored. If any other exception occurs, the test will fail. See
// the putAI.exceptionOccurred() assertion below.
AsyncInvocation putAI = vm2.invokeAsync(new CacheSerializableRunnable("Put objects") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
try {
for (int i = 0; i < 100000; i++) {
region.put("keyAI", new Integer(i));
try {
Thread.sleep(100);
} catch (InterruptedException ie) {
fail("interrupted");
}
}
} catch (NoAvailableServersException ignore) {
/* ignore */
} catch (RegionDestroyedException e) {
// will be thrown when the test ends
/* ignore */
} catch (CancelException e) {
// will be thrown when the test ends
/* ignore */
}
}
});
SerializableRunnable verify1Server = new CacheSerializableRunnable("verify1Server") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
PoolImpl pool = getPool(region);
verifyServerCount(pool, 1);
}
};
SerializableRunnable verify2Servers = new CacheSerializableRunnable("verify2Servers") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
PoolImpl pool = getPool(region);
verifyServerCount(pool, 2);
}
};
vm2.invoke(verify2Servers);
SerializableRunnable stopCacheServer = new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
};
final String expected = "java.io.IOException";
final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
vm2.invoke(new SerializableRunnable() {
public void run() {
LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
bgexecLogger.info(addExpected);
}
});
try {
// make sure we removeExpected
// Bounce the non-current server (I know that VM1 contains the non-current server
// because ...
vm1.invoke(stopCacheServer);
vm2.invoke(verify1Server);
final int restartPort = port1;
vm1.invoke(new SerializableRunnable("Restart CacheServer") {
public void run() {
try {
Region region = getRootRegion().getSubregion(name);
assertNotNull(region);
startBridgeServer(restartPort);
} catch (Exception e) {
getSystem().getLogWriter().fine(new Exception(e));
org.apache.geode.test.dunit.Assert.fail("Failed to start CacheServer", e);
}
}
});
// Pause long enough for the monitor to realize the server has been bounced
// and reconnect to it.
vm2.invoke(verify2Servers);
} finally {
vm2.invoke(new SerializableRunnable() {
public void run() {
LogWriter bgexecLogger = new LocalLogWriter(InternalLogWriter.ALL_LEVEL, System.out);
bgexecLogger.info(removeExpected);
}
});
}
// Stop the other cache server
vm0.invoke(stopCacheServer);
// Run awhile
vm2.invoke(verify1Server);
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info(// FIXME
"FIXME: this thread does not terminate");
// // Verify that no exception has occurred in the putter thread
// join(putAI, 5 * 60 * 1000, getLogWriter());
// //assertTrue("Exception occurred while invoking " + putAI, !putAI.exceptionOccurred());
// if (putAI.exceptionOccurred()) {
// fail("While putting entries: ", putAI.getException());
// }
// Close Pool
vm2.invoke(new CacheSerializableRunnable("Close Pool") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.localDestroyRegion();
}
});
// Stop the last cache server
vm1.invoke(stopCacheServer);
}
use of org.apache.geode.cache30.CacheSerializableRunnable 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.CacheSerializableRunnable in project geode by apache.
the class ConnectionPoolDUnitTest method test021ClientGetOfInvalidServerEntry.
// test for bug 35884
@Test
public void test021ClientGetOfInvalidServerEntry() throws CacheException {
final String regionName1 = this.getName() + "-1";
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM client = host.getVM(2);
SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setConcurrencyChecksEnabled(false);
createRegion(regionName1, factory.create());
Wait.pause(1000);
try {
startBridgeServer(0);
} catch (Exception ex) {
org.apache.geode.test.dunit.Assert.fail("While starting CacheServer", ex);
}
}
};
// Create server1.
server1.invoke(createServer);
final int port = server1.invoke(() -> ConnectionPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server1.getHost());
// Init values at server.
server1.invoke(new CacheSerializableRunnable("Create values") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
// create it invalid
region1.create("key-string-1", null);
}
});
// now try it with a local scope
SerializableRunnable createPool2 = new CacheSerializableRunnable("Create region 2") {
public void run2() throws CacheException {
// Region region1 = getRootRegion().getSubregion(regionName1);
// region1.localDestroyRegion();
getLonerSystem();
AttributesFactory regionFactory = new AttributesFactory();
regionFactory.setScope(Scope.LOCAL);
regionFactory.setConcurrencyChecksEnabled(false);
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("ZZZZZ host0:" + host0 + " port:" + port);
ClientServerTestCase.configureConnectionPool(regionFactory, host0, port, -1, false, -1, -1, null);
org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("ZZZZZDone host0:" + host0 + " port:" + port);
createRegion(regionName1, regionFactory.create());
}
};
client.invoke(createPool2);
// get the invalid entry on the client.
client.invoke(new CacheSerializableRunnable("get values on client") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regionName1);
assertEquals(null, region1.getEntry("key-string-1"));
assertEquals(null, region1.get("key-string-1"));
}
});
server1.invoke(new SerializableRunnable("Stop CacheServer") {
public void run() {
stopBridgeServer(getCache());
}
});
}
Aggregations