use of org.apache.geode.internal.cache.RegionQueue in project geode by apache.
the class ParallelGatewaySenderQueueOverflowDUnitTest method test_ValidateParallelGatewaySenderQueueAttributes_1.
/**
* Test to validate that ParallelGatewaySenderQueue diskSynchronous attribute when persistence of
* sender is enabled.
*/
@Ignore("TODO: test is disabled")
@Test
public void test_ValidateParallelGatewaySenderQueueAttributes_1() {
Integer localLocPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
Integer remoteLocPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, localLocPort));
WANTestBase test = new WANTestBase();
Properties props = test.getDistributedSystemProperties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "localhost[" + localLocPort + "]");
InternalDistributedSystem ds = test.getSystem(props);
cache = CacheFactory.create(ds);
File directory = new File("TKSender" + "_disk_" + System.currentTimeMillis() + "_" + VM.getCurrentVMNum());
directory.mkdir();
File[] dirs1 = new File[] { directory };
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setDiskDirs(dirs1);
DiskStore diskStore = dsf.create("FORNY");
GatewaySenderFactory fact = cache.createGatewaySenderFactory();
// set parallel to true
fact.setParallel(true);
fact.setBatchConflationEnabled(true);
fact.setBatchSize(200);
fact.setBatchTimeInterval(300);
// enable the persistence
fact.setPersistenceEnabled(true);
fact.setDiskSynchronous(true);
fact.setDiskStoreName("FORNY");
fact.setMaximumQueueMemory(200);
fact.setAlertThreshold(1200);
GatewayEventFilter myEventFilter1 = new MyGatewayEventFilter1();
fact.addGatewayEventFilter(myEventFilter1);
GatewayTransportFilter myStreamFilter1 = new MyGatewayTransportFilter1();
fact.addGatewayTransportFilter(myStreamFilter1);
GatewayTransportFilter myStreamFilter2 = new MyGatewayTransportFilter2();
fact.addGatewayTransportFilter(myStreamFilter2);
final IgnoredException exTKSender = IgnoredException.addIgnoredException("Could not connect");
try {
GatewaySender sender1 = fact.create("TKSender", 2);
AttributesFactory factory = new AttributesFactory();
factory.addGatewaySenderId(sender1.getId());
factory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
Region region = cache.createRegionFactory(factory.create()).create("test_ValidateGatewaySenderAttributes");
Set<GatewaySender> senders = cache.getGatewaySenders();
assertEquals(senders.size(), 1);
GatewaySender gatewaySender = senders.iterator().next();
Set<RegionQueue> regionQueues = ((AbstractGatewaySender) gatewaySender).getQueues();
assertEquals(regionQueues.size(), 1);
RegionQueue regionQueue = regionQueues.iterator().next();
assertEquals(true, regionQueue.getRegion().getAttributes().isDiskSynchronous());
} finally {
exTKSender.remove();
}
}
use of org.apache.geode.internal.cache.RegionQueue in project geode by apache.
the class MyGatewayEventSubstitutionFilter method waitForAsyncEventQueueSize.
/**
* This method verifies the queue size of a ParallelGatewaySender. For ParallelGatewaySender
* conflation happens in a separate thread, hence test code needs to wait for some time for
* expected result
*
* @param asyncQueueId Async Queue ID
* @param numQueueEntries expected number of Queue entries
* @throws Exception
*/
public static void waitForAsyncEventQueueSize(String asyncQueueId, final int numQueueEntries) throws Exception {
AsyncEventQueue theAsyncEventQueue = null;
Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues();
for (AsyncEventQueue asyncChannel : asyncEventChannels) {
if (asyncQueueId.equals(asyncChannel.getId())) {
theAsyncEventQueue = asyncChannel;
}
}
GatewaySender sender = ((AsyncEventQueueImpl) theAsyncEventQueue).getSender();
if (sender.isParallel()) {
final Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
Wait.waitForCriterion(new WaitCriterion() {
public String description() {
return "Waiting for EventQueue size to be " + numQueueEntries;
}
public boolean done() {
boolean done = numQueueEntries == queues.toArray(new RegionQueue[queues.size()])[0].getRegion().size();
return done;
}
}, MAX_WAIT, 500, true);
} else {
throw new Exception("This method should be used for only ParallelGatewaySender,SerialGatewaySender should use checkAsyncEventQueueSize() method instead");
}
}
use of org.apache.geode.internal.cache.RegionQueue in project geode by apache.
the class MyGatewayEventSubstitutionFilter method checkAsyncEventQueueSize.
public static void checkAsyncEventQueueSize(String asyncQueueId, int numQueueEntries) {
AsyncEventQueue theAsyncEventQueue = null;
Set<AsyncEventQueue> asyncEventChannels = cache.getAsyncEventQueues();
for (AsyncEventQueue asyncChannel : asyncEventChannels) {
if (asyncQueueId.equals(asyncChannel.getId())) {
theAsyncEventQueue = asyncChannel;
}
}
GatewaySender sender = ((AsyncEventQueueImpl) theAsyncEventQueue).getSender();
if (sender.isParallel()) {
Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
assertEquals(numQueueEntries, queues.toArray(new RegionQueue[queues.size()])[0].getRegion().size());
} else {
Set<RegionQueue> queues = ((AbstractGatewaySender) sender).getQueues();
int size = 0;
for (RegionQueue q : queues) {
size += q.size();
}
assertEquals(numQueueEntries, size);
}
}
use of org.apache.geode.internal.cache.RegionQueue in project geode by apache.
the class HARegionQueueJUnitTest method testQRM.
/**
* Tests whether the QRM message removes the events correctly from the DACE & Conflation Map. The
* events which are of ID greater than that contained in QRM should stay
*/
@Test
public void testQRM() throws Exception {
RegionQueue regionqueue = createHARegionQueue(this.testName.getMethodName());
for (int i = 0; i < 10; ++i) {
regionqueue.put(new ConflatableObject("key" + (i + 1), "value", new EventID(new byte[] { 1 }, 1, i + 1), true, this.testName.getMethodName()));
}
EventID qrmID = new EventID(new byte[] { 1 }, 1, 5);
((HARegionQueue) regionqueue).removeDispatchedEvents(qrmID);
Map conflationMap = ((HARegionQueue) regionqueue).getConflationMapForTesting();
assertThat(((Map) conflationMap.get(this.testName.getMethodName())).size(), is(5));
Set availableIDs = ((HARegionQueue) regionqueue).getAvalaibleIds();
Set counters = ((HARegionQueue) regionqueue).getCurrentCounterSet(qrmID);
assertThat(availableIDs.size(), is(5));
assertThat(counters.size(), is(5));
for (int i = 5; i < 10; ++i) {
assertThat(((Map) (conflationMap.get(this.testName.getMethodName()))).containsKey("key" + (i + 1)), is(true));
assertThat(availableIDs.contains((long) (i + 1)), is(true));
assertThat(counters.contains((long) (i + 1)), is(true));
}
Region rgn = ((HARegionQueue) regionqueue).getRegion();
assertThat(rgn.keySet().size(), is(6));
}
use of org.apache.geode.internal.cache.RegionQueue in project geode by apache.
the class HARegionQueueJUnitTest method testConcurrentEventExpiryAndTake.
/**
* The basis of HARegionQueue's Add & remove operations etc , is that the event being added first
* goes into DACE , Region etc and finally it is published by adding into the available IDs Set.
* Similarly if an event is to be removed it should first be removed from availableIDs set & then
* from behind the scenes. It will be the responsibility of the thread removing from available IDs
* successfully which will remove the entry from all other places. Now if the expiry task makes
* the event from underlying null before removing from available IDs , there is a potential
* violation. This test will validate that behaviour
*/
@Test
public void testConcurrentEventExpiryAndTake() throws Exception {
AtomicBoolean complete = new AtomicBoolean(false);
AtomicBoolean expiryCalled = new AtomicBoolean(false);
AtomicBoolean allowExpiryToProceed = new AtomicBoolean(false);
HARegionQueueAttributes haa = new HARegionQueueAttributes();
haa.setExpiryTime(3);
RegionQueue regionqueue = new HARegionQueue.TestOnlyHARegionQueue(this.testName.getMethodName(), this.cache, haa) {
@Override
CacheListener createCacheListenerForHARegion() {
return new CacheListenerAdapter() {
@Override
public void afterInvalidate(EntryEvent event) {
if (event.getKey() instanceof Long) {
synchronized (HARegionQueueJUnitTest.this) {
expiryCalled.set(true);
HARegionQueueJUnitTest.this.notifyAll();
}
Thread.yield();
synchronized (HARegionQueueJUnitTest.this) {
while (!allowExpiryToProceed.get()) {
try {
HARegionQueueJUnitTest.this.wait();
} catch (InterruptedException e) {
errorCollector.addError(e);
break;
}
}
}
try {
expireTheEventOrThreadIdentifier(event);
} catch (CacheException e) {
errorCollector.addError(e);
} finally {
synchronized (HARegionQueueJUnitTest.this) {
complete.set(true);
HARegionQueueJUnitTest.this.notifyAll();
}
}
}
}
};
}
};
EventID ev1 = new EventID(new byte[] { 1 }, 1, 1);
Conflatable cf1 = new ConflatableObject("key", "value", ev1, true, this.testName.getMethodName());
regionqueue.put(cf1);
synchronized (this) {
while (!expiryCalled.get()) {
wait();
}
}
try {
Object o = regionqueue.take();
assertThat(o, nullValue());
} catch (Exception e) {
throw new AssertionError("Test failed due to exception ", e);
} finally {
synchronized (this) {
allowExpiryToProceed.set(true);
notifyAll();
}
}
synchronized (this) {
while (!complete.get()) {
wait();
}
}
}
Aggregations