use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class ConflationDUnitTest method registerInterest.
/**
* register interest with the server on ALL_KEYS
*
*/
public static void registerInterest() {
try {
Region region1 = cache.getRegion(Region.SEPARATOR + REGION_NAME1);
Region region2 = cache.getRegion(Region.SEPARATOR + REGION_NAME2);
assertTrue(region1 != null);
assertTrue(region2 != null);
region1.registerInterest("ALL_KEYS");
region2.registerInterest("ALL_KEYS");
} catch (CacheWriterException e) {
fail("test failed due to " + e);
}
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class InterestListEndpointDUnitTest method testInterestListEndpointAfterFailover.
@Test
public void testInterestListEndpointAfterFailover() throws Exception {
final long maxWaitTime = 20000;
client1.invoke(() -> createEntriesK1andK2());
server2.invoke(() -> createEntriesK1andK2());
server1.invoke(() -> createEntriesK1andK2());
client1.invoke(() -> registerKey1());
boolean firstIsPrimary = isVm0Primary();
VM primary = firstIsPrimary ? server1 : server2;
primary.invoke(() -> stopILEndpointServer());
Wait.pause(5000);
// Since the loadbalancing policy is roundrobin & there are two servers so
// do two dumb puts, which will ensure that fail over happens from the
// interest list end point in case Live ServerMonitor is not working
client1.invoke(new CacheSerializableRunnable("Ensure that the failover from ILEP occurs") {
public void run2() throws CacheException {
Region r = cache.getRegion("/" + REGION_NAME);
String poolName = r.getAttributes().getPoolName();
assertNotNull(poolName);
final PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
assertNotNull(pool);
pool.acquireConnection();
try {
// Used in the case where we don't have a LiveServerMonitorThread
r.put("ping", "pong1");
} catch (CacheWriterException itsOK) {
}
try {
// Used in the case where we don't have a LiveServerMonitorThread
r.put("ping", "pong2");
} catch (CacheWriterException itsOK) {
}
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return pool.getConnectedServerCount() != 2;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, maxWaitTime, 200, true);
}
});
// put on stopped server
primary.invoke(() -> put());
client1.invoke(() -> verifyPut());
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class DestroyEntryPropagationDUnitTest method testVerifyDestroyNotReceivedBySender.
/**
* This tests whether the destroy are received by the sender or not if there are situation of
* Interest List fail over
*/
// GEODE-897: random port, time sensitive, waitForCriterion, 2 minute
@Category(FlakyTest.class)
// timeouts, eats exception (1 fixed)
@Test
public void testVerifyDestroyNotReceivedBySender() {
final int maxWaitTime = Integer.getInteger(WAIT_PROPERTY, WAIT_DEFAULT).intValue();
// First create entries on both servers via the two client
vm2.invoke(() -> DestroyEntryPropagationDUnitTest.createEntriesK1andK2());
vm3.invoke(() -> DestroyEntryPropagationDUnitTest.createEntriesK1andK2());
vm2.invoke(() -> DestroyEntryPropagationDUnitTest.registerKey1());
vm3.invoke(() -> DestroyEntryPropagationDUnitTest.registerKey1());
// Induce fail over of InterestList Endpoint to Server 2 by killing server1
vm0.invoke(() -> DestroyEntryPropagationDUnitTest.killServer(new Integer(PORT1)));
// Wait for 10 seconds to allow fail over. This would mean that Interest
// has failed over to Server2.
vm2.invoke(new CacheSerializableRunnable("Wait for server on port1 to be dead") {
public void run2() throws CacheException {
Region r = cache.getRegion(REGION_NAME);
try {
// Used in the case where we don't have a LiveServerMonitorThread
r.put("ping", "pong1");
} catch (CacheWriterException itsOK) {
}
try {
// Used in the case where we don't have a LiveServerMonitorThread
r.put("ping", "pong1");
} catch (CacheWriterException itsOK) {
}
String poolName = r.getAttributes().getPoolName();
assertNotNull(poolName);
final PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
assertNotNull(pool);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return pool.getConnectedServerCount() != 2;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, maxWaitTime, 200, true);
}
});
// Start Server1 again so that both clients1 & Client 2 will establish
// connection to server1 too.
vm0.invoke(() -> DestroyEntryPropagationDUnitTest.startServer(new Integer(PORT1)));
vm2.invoke(new CacheSerializableRunnable("Wait for server on port1 to spring to life") {
public void run2() throws CacheException {
Region r = cache.getRegion(REGION_NAME);
String poolName = r.getAttributes().getPoolName();
assertNotNull(poolName);
final PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
assertNotNull(pool);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return pool.getConnectedServerCount() == 2;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, maxWaitTime, 200, true);
}
});
// Do a destroy on Server1 via Connection object from client1.
// Client1 should not receive updated value while client2 should receive
vm2.invoke(() -> acquireConnectionsAndDestroyEntriesK1andK2());
// pause(10000);
// Check if both the puts ( on key1 & key2 ) have reached the servers
vm0.invoke(() -> DestroyEntryPropagationDUnitTest.verifyEntriesAreDestroyed());
vm1.invoke(() -> DestroyEntryPropagationDUnitTest.verifyEntriesAreDestroyed());
vm2.invoke(() -> DestroyEntryPropagationDUnitTest.verifyNoDestroyEntryInSender());
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class InterestResultPolicyDUnitTest method registerInterest.
/**
* Registers the test region on client with a keylist containing all keys pre-populated on server
* and a given {@link InterestResultPolicy} type.
*
* @param interestPolicy - InterestResultPolicy type specified (NONE,KEYS,KEY_VALUES or DEFAULT)
*/
public static void registerInterest(Object interestPolicy, Object totalKeysToRegister) {
InterestResultPolicy policy = (InterestResultPolicy) interestPolicy;
int totalKeys = ((Integer) totalKeysToRegister).intValue();
Region region1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
LogWriter logger = cache.getLogger();
logger.fine("Registering interest in " + totalKeys + " keys");
List keylist = new ArrayList();
for (int i = 0; i < totalKeys; i++) {
keylist.add("key-" + i);
}
try {
region1.registerInterest(keylist, policy);
} catch (CacheWriterException e) {
Assert.fail("failed to register interestlist for the client", e);
}
}
use of org.apache.geode.cache.CacheWriterException in project geode by apache.
the class GemcachedBinaryClientJUnitTest method testCacheWriterException.
@SuppressWarnings("unchecked")
public void testCacheWriterException() throws Exception {
MemcachedClient client = createMemcachedClient();
assertTrue(client.set("key", 0, "value".getBytes()).get());
client.set("exceptionkey", 0, "exceptionvalue").get();
GemFireCacheImpl cache = GemFireCacheImpl.getInstance();
Region region = cache.getRegion(GemFireMemcachedServer.REGION_NAME);
region.getAttributesMutator().setCacheWriter(new CacheWriterAdapter() {
@Override
public void beforeCreate(EntryEvent event) throws CacheWriterException {
if (event.getKey().equals(KeyWrapper.getWrappedKey("exceptionkey".getBytes()))) {
throw new RuntimeException("ExpectedStrings: Cache writer exception");
}
}
@Override
public void beforeUpdate(EntryEvent event) throws CacheWriterException {
if (event.getKey().equals(KeyWrapper.getWrappedKey("exceptionkey".getBytes()))) {
throw new RuntimeException("ExpectedStrings: Cache writer exception");
}
}
});
long start = System.nanoTime();
try {
client.set("exceptionkey", 0, "exceptionvalue").get();
throw new RuntimeException("expected exception not thrown");
} catch (ExecutionException e) {
// expected
}
assertTrue(client.set("key2", 0, "value2".getBytes()).get());
}
Aggregations