use of org.apache.geode.internal.cache.Conflatable in project geode by apache.
the class HARegionQueueStatsJUnitTest method testVoidRemovalStats.
/**
* This test does the following:<br>
* 1)Create HARegionQueue.<br>
* 2)Add objects with unique eventids and conflation false<br>
* 3)peek a batch to peek all the events added and take() all the events<br>
* 4)Call remove()<br>
* 5)Verify that statistics object is not null<br>
* 6)Verify that total events added matches the eventsEnqued stats<br>
* 7)Verify that numVoidRemovals stats is same as the total events added since all the peeked
* events were removed by take() call and remove() was a void operation.
*
* @throws Exception - thrown if any problem occurs in test execution
*/
@Test
public void testVoidRemovalStats() throws Exception {
HARegionQueue rq = createHARegionQueue("testVoidRemovalStats");
Conflatable cf = null;
int totalEvents = 100;
for (int i = 0; i < totalEvents; i++) {
cf = new ConflatableObject("key" + i, "value" + i, new EventID(new byte[] { 1 }, 1, i), false, "testing");
rq.put(cf);
}
rq.peek(totalEvents);
rq.take(totalEvents);
rq.remove();
HARegionQueueStats stats = rq.getStatistics();
assertNotNull("stats for HARegionQueue found null", stats);
assertEquals("eventsEnqued by stats not equal to the actual number of events added to the queue", totalEvents, stats.getEventsEnqued());
assertEquals("Number of void removals shud be equal to total peeked since all the events were removed by take() before remove()", totalEvents, stats.getNumVoidRemovals());
}
use of org.apache.geode.internal.cache.Conflatable in project geode by apache.
the class HARegionQueueStatsJUnitTest method testPutStatsNoConflation.
/**
* This test does the following:<br>
* 1)Create HARegionQueue<br>
* 2)Add objects with unique eventids and conflation false <br>
* 3)Verify that statistics object is not null<br>
* 4)Verify that total events added matches the eventsEnqued stats<br>
* 5)Verify that eventsConflated stats is zero.
*
* @throws Exception - thrown if any problem occurs in test execution
*/
@Test
public void testPutStatsNoConflation() throws Exception {
HARegionQueue rq = createHARegionQueue("testPutStatsNoConflation");
Conflatable cf = null;
int totalEvents = 100;
for (int i = 0; i < totalEvents; i++) {
cf = new ConflatableObject("key" + i, "value" + i, new EventID(new byte[] { 1 }, 1, i), false, "testing");
rq.put(cf);
}
HARegionQueueStats stats = rq.getStatistics();
assertNotNull("stats for HARegionQueue found null", stats);
assertEquals("eventsEnqued by stats not equal to the actual number of events added to the queue", totalEvents, stats.getEventsEnqued());
assertEquals("eventsConflated by stats not equal zero", 0, stats.getEventsConflated());
}
use of org.apache.geode.internal.cache.Conflatable in project geode by apache.
the class BlockingHARegionQueueJUnitTest method testBlockingPutAndTake.
/**
* Tests the effect of a put which is blocked because of capacity constraint & subsequent passage
* because of take operation
*/
@Test
public void testBlockingPutAndTake() throws Exception {
HARegionQueueAttributes hrqa = new HARegionQueueAttributes();
hrqa.setBlockingQueueCapacity(1);
HARegionQueue hrq = createHARegionQueue(this.testName.getMethodName(), hrqa);
// fix for 40314 - capacity constraint is checked for primary only.
hrq.setPrimary(true);
EventID id1 = new EventID(new byte[] { 1 }, 1, 1);
hrq.put(new ConflatableObject("key1", "val1", id1, false, "testing"));
AtomicBoolean threadStarted = new AtomicBoolean(false);
Thread thread = new Thread(() -> {
try {
threadStarted.set(true);
EventID id2 = new EventID(new byte[] { 1 }, 1, 2);
hrq.put(new ConflatableObject("key1", "val2", id2, false, "testing"));
} catch (InterruptedException e) {
errorCollector.addError(e);
}
});
thread.start();
Awaitility.await().atMost(1, TimeUnit.MINUTES).until(() -> threadStarted.get());
Conflatable conf = (Conflatable) hrq.take();
assertThat(conf, notNullValue());
Awaitility.await().atMost(1, TimeUnit.MINUTES).until(() -> !thread.isAlive());
}
use of org.apache.geode.internal.cache.Conflatable in project geode by apache.
the class HARegionQueue method basicPut.
private void basicPut(Object object) throws CacheException, InterruptedException {
// optmistically decrease the put count
try {
this.checkQueueSizeConstraint();
// this.region.checkReadiness(); // throws CacheClosed or RegionDestroyed
} catch (InterruptedException ie) {
Thread.currentThread().interrupt();
this.region.getCache().getCancelCriterion().checkCancelInProgress(ie);
}
Conflatable event = (Conflatable) object;
// Get the EventID object & from it obtain the ThreadIdentifier
EventID eventId = event.getEventId();
ThreadIdentifier ti = getThreadIdentifier(eventId);
long sequenceID = eventId.getSequenceID();
// Check from Events Map if the put operation should proceed or not
DispatchedAndCurrentEvents dace = (DispatchedAndCurrentEvents) this.eventsMap.get(ti);
if (dace != null && dace.isGIIDace && this.puttingGIIDataInQueue) {
// we only need to retain DACE for which there are no entries in the queue.
// for other thread identifiers we build up a new DACE
dace = null;
}
if (dace != null) {
// check the last dispatched sequence Id
if (this.puttingGIIDataInQueue || (sequenceID > dace.lastDispatchedSequenceId)) {
// also does not get added
if (!dace.putObject(event, sequenceID)) {
// dace encountered a DESTROYED token - stop adding GII data
if (!this.puttingGIIDataInQueue) {
this.put(object);
}
} else {
if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
logger.trace(LogMarker.BRIDGE_SERVER, "{}: Adding message to queue: {}", this, object);
}
}
} else {
if (logger.isDebugEnabled()) {
logger.debug("{}: This queue has already seen this event. The highest sequence number in the queue for {} is {}, but this event's sequence number is {}", this.regionName, ti, dace.lastDispatchedSequenceId, sequenceID);
}
incrementTakeSidePutPermits();
}
} else {
dace = new DispatchedAndCurrentEvents(this);
DispatchedAndCurrentEvents oldDace = (DispatchedAndCurrentEvents) this.eventsMap.putIfAbsent(ti, dace);
if (oldDace != null) {
dace = oldDace;
} else {
// Add the recently added ThreadIdentifier to the RegionQueue for expiry
this.region.put(ti, dace.lastDispatchedSequenceId);
// update the stats
this.stats.incThreadIdentifiers();
}
if (!dace.putObject(event, sequenceID)) {
this.put(object);
} else {
if (logger.isTraceEnabled(LogMarker.BRIDGE_SERVER)) {
logger.trace(LogMarker.BRIDGE_SERVER, "{}: Adding message to queue: {}", this, object);
}
}
}
}
use of org.apache.geode.internal.cache.Conflatable in project geode by apache.
the class SerialGatewaySenderQueue method putAndGetKeyNoSync.
private long putAndGetKeyNoSync(Object object) throws CacheException {
// don't sync on whole put; callers will do the puts in parallel but
// will wait later for previous tailKey put to complete after its own
// put is done
Long key;
synchronized (this) {
initializeKeys();
// Get and increment the current key
// Go for full sync in case of wrapover
long ckey = this.currentKey;
if (logger.isTraceEnabled()) {
logger.trace("{}: Determined current key: {}", this, ckey);
}
key = Long.valueOf(ckey);
this.currentKey = inc(ckey);
}
try {
// Put the object into the region at that key
this.region.put(key, (AsyncEvent) object);
if (logger.isDebugEnabled()) {
logger.debug("{}: Inserted {} -> {}", this, key, object);
}
} finally {
final Object sync = this.pendingPuts;
synchronized (sync) {
while (true) {
if (key.longValue() == this.tailKey.get()) {
// this is the next thread, so increment tail and signal all other
// waiting threads if required
incrementTailKey();
// check pendingPuts
boolean notifyWaiters = false;
if (this.pendingPuts.size() > 0) {
Iterator<Long> itr = this.pendingPuts.iterator();
while (itr.hasNext()) {
Long k = itr.next();
if (k.longValue() == this.tailKey.get()) {
incrementTailKey();
// removed something from pending queue, so notify any waiters
if (!notifyWaiters) {
notifyWaiters = (this.pendingPuts.size() >= this.maxPendingPuts);
}
itr.remove();
} else {
break;
}
}
}
if (notifyWaiters) {
sync.notifyAll();
}
break;
} else if (this.pendingPuts.size() < this.maxPendingPuts) {
this.pendingPuts.add(key);
break;
} else {
// wait for the queue size to go down
boolean interrupted = Thread.interrupted();
Throwable t = null;
try {
sync.wait(5);
} catch (InterruptedException ie) {
t = ie;
interrupted = true;
} finally {
if (interrupted) {
Thread.currentThread().interrupt();
}
((LocalRegion) this.region).getCancelCriterion().checkCancelInProgress(t);
}
}
}
}
}
if (object instanceof Conflatable) {
removeOldEntry((Conflatable) object, key);
}
return key.longValue();
}
Aggregations