use of org.apache.geode.distributed.internal.DMStats in project geode by apache.
the class SlowRecDUnitTest method testNoAck.
/**
* Make sure that noack puts to a receiver will eventually queue and then catch up.
*/
@Test
public void testNoAck() throws Exception {
final AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_NO_ACK);
final Region r = createRootRegion("slowrec", factory.create());
final DMStats stats = getSystem().getDistributionManager().getStats();
// create receiver in vm0 with queuing enabled
Properties p = new Properties();
p.setProperty(ASYNC_DISTRIBUTION_TIMEOUT, "1");
doCreateOtherVm(p, false);
int repeatCount = 2;
int count = 0;
while (repeatCount-- > 0) {
forceQueuing(r);
final Object key = "key";
long queuedMsgs = stats.getAsyncQueuedMsgs();
long dequeuedMsgs = stats.getAsyncDequeuedMsgs();
long queueSize = stats.getAsyncQueueSize();
String lastValue = "";
final long intialQueuedMsgs = queuedMsgs;
long curQueuedMsgs = queuedMsgs - dequeuedMsgs;
try {
// OR the cur # of queued msgs < 6
while (dequeuedMsgs < intialQueuedMsgs || curQueuedMsgs <= 6) {
String value = "count=" + count;
lastValue = value;
r.put(key, value);
count++;
queueSize = stats.getAsyncQueueSize();
queuedMsgs = stats.getAsyncQueuedMsgs();
dequeuedMsgs = stats.getAsyncDequeuedMsgs();
curQueuedMsgs = queuedMsgs - dequeuedMsgs;
}
LogWriterUtils.getLogWriter().info("After " + count + " " + " puts slowrec mode kicked in by queuing " + queuedMsgs + " for a total size of " + queueSize);
} finally {
forceQueueFlush();
}
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return stats.getAsyncQueueSize() == 0;
}
public String description() {
return "Waiting for queues to empty";
}
};
final long start = System.currentTimeMillis();
Wait.waitForCriterion(ev, 30 * 1000, 200, true);
final long finish = System.currentTimeMillis();
LogWriterUtils.getLogWriter().info("After " + (finish - start) + " ms async msgs where flushed. A total of " + stats.getAsyncDequeuedMsgs() + " were flushed. lastValue=" + lastValue);
checkLastValueInOtherVm(lastValue, null);
}
}
use of org.apache.geode.distributed.internal.DMStats in project geode by apache.
the class SlowRecDUnitTest method testAckConflation.
/**
* make sure ack does not hang make sure two ack updates do not conflate but are both queued
*/
@Test
public void testAckConflation() throws Exception {
final AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_NO_ACK);
factory.setEnableAsyncConflation(true);
final Region r = createRootRegion("slowrec", factory.create());
final Region ar = createAckRegion(false, true);
ar.create("ackKey", "ackValue");
final DMStats stats = getSystem().getDistributionManager().getStats();
// create receiver in vm0 with queuing enabled
Properties p = new Properties();
p.setProperty(ASYNC_DISTRIBUTION_TIMEOUT, "2");
doCreateOtherVm(p, false);
forceQueuing(r);
{
// make sure ack does not hang
// make sure two ack updates do not conflate but are both queued
long startQueuedMsgs = stats.getAsyncQueuedMsgs();
long startConflatedMsgs = stats.getAsyncConflatedMsgs();
Thread t = new Thread(new Runnable() {
public void run() {
ar.put("ackKey", "ackValue");
}
});
t.start();
Thread t2 = new Thread(new Runnable() {
public void run() {
ar.put("ackKey", "ackValue");
}
});
t2.start();
// give threads a chance to get queued
try {
Thread.sleep(100);
} catch (InterruptedException ignore) {
fail("interrupted");
}
forceQueueFlush();
ThreadUtils.join(t, 2 * 1000);
ThreadUtils.join(t2, 2 * 1000);
long endQueuedMsgs = stats.getAsyncQueuedMsgs();
long endConflatedMsgs = stats.getAsyncConflatedMsgs();
assertEquals(startConflatedMsgs, endConflatedMsgs);
// queue should be flushed by the time we get an ack
assertEquals(endQueuedMsgs, stats.getAsyncDequeuedMsgs());
assertEquals(startQueuedMsgs + 2, endQueuedMsgs);
}
}
use of org.apache.geode.distributed.internal.DMStats in project geode by apache.
the class SlowRecDUnitTest method doTestMultipleRegionConflation.
private void doTestMultipleRegionConflation() throws Exception {
final AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_NO_ACK);
factory.setEnableAsyncConflation(true);
final Region r1 = createRootRegion("slowrec1", factory.create());
final Region r2 = createRootRegion("slowrec2", factory.create());
assertTrue(getSystem().isConnected());
assertNotNull(r1);
assertFalse(r1.isDestroyed());
assertNotNull(getCache());
assertNotNull(getCache().getRegion("slowrec1"));
assertNotNull(r2);
assertFalse(r2.isDestroyed());
assertNotNull(getCache());
assertNotNull(getCache().getRegion("slowrec2"));
final DM dm = getSystem().getDistributionManager();
final Serializable controllerVM = dm.getDistributionManagerId();
final DMStats stats = dm.getStats();
// 5 minutes
final int millisToWait = 1000 * 60 * 5;
// set others before vm0 connects
long initialQueuedMsgs = stats.getAsyncQueuedMsgs();
// create receiver in vm0 with queuing enabled
final Properties p = new Properties();
p.setProperty(ASYNC_DISTRIBUTION_TIMEOUT, "5");
// max value
p.setProperty(ASYNC_QUEUE_TIMEOUT, "86400000");
// max value
p.setProperty(ASYNC_MAX_QUEUE_SIZE, "1024");
getOtherVm().invoke(new CacheSerializableRunnable("Create other vm") {
public void run2() throws CacheException {
getSystem(p);
DM dm = getSystem().getDistributionManager();
assertTrue(dm.getDistributionManagerIds().contains(controllerVM));
AttributesFactory af = new AttributesFactory();
af.setScope(Scope.DISTRIBUTED_NO_ACK);
af.setDataPolicy(DataPolicy.REPLICATE);
doTestMultipleRegionConflation_R1_Listener = new ControlListener();
af.setCacheListener(doTestMultipleRegionConflation_R1_Listener);
createRootRegion("slowrec1", af.create());
doTestMultipleRegionConflation_R2_Listener = new ControlListener();
af.setCacheListener(doTestMultipleRegionConflation_R2_Listener);
createRootRegion("slowrec2", af.create());
}
});
// put vm0 cache listener into wait
LogWriterUtils.getLogWriter().info("[doTestMultipleRegionConflation] about to put vm0 into wait");
r1.put(KEY_WAIT, new Integer(millisToWait));
// build up queue size
LogWriterUtils.getLogWriter().info("[doTestMultipleRegionConflation] building up queue size...");
final Object key = "key";
final int socketBufferSize = getSystem().getConfig().getSocketBufferSize();
final int VALUE_SIZE = socketBufferSize * 3;
// final int VALUE_SIZE = 1024 * 1024 ; // 1 MB
final byte[] value = new byte[VALUE_SIZE];
int count = 0;
while (stats.getAsyncQueuedMsgs() == initialQueuedMsgs) {
count++;
r1.put(key, value);
}
LogWriterUtils.getLogWriter().info("[doTestMultipleRegionConflation] After " + count + " puts of size " + VALUE_SIZE + " slowrec mode kicked in with queue size=" + stats.getAsyncQueueSize());
// put values that will be asserted
final Object key1 = "key1";
final Object key2 = "key2";
Object putKey = key1;
boolean flag = true;
for (int i = 0; i < 30; i++) {
if (i == 10)
putKey = key2;
if (flag) {
if (i == 6) {
r1.invalidate(putKey, new Integer(i));
} else if (i == 24) {
r1.invalidateRegion(new Integer(i));
} else {
r1.put(putKey, value, new Integer(i));
}
} else {
if (i == 15) {
r2.destroy(putKey, new Integer(i));
} else {
r2.put(putKey, value, new Integer(i));
}
}
flag = !flag;
}
// r1: key1, 0, create
// r1: key1, 4, update
// r1: key1, 6, invalidate
// r1: key1, 8, update
// r1: key2, 10, create
// r1: 24, invalidateRegion
// r1: key2, 28, update
// r2: key1, 1, create
// r2: key1, 9, update
// r2: key2, 11, create
// r2: key2, 13, update
// r2: key2, 15, destroy
// r2: key2, 17, create
// r2: key2, 29, update
final int[] r1ExpectedArgs = new int[] { 0, 4, 6, 8, 10, 24, 28 };
final int[] r1ExpectedTypes = new int[] /* 0, 1, 2, 1, 0, 4, 1 */
{ CALLBACK_CREATE, CALLBACK_UPDATE, CALLBACK_INVALIDATE, CALLBACK_UPDATE, CALLBACK_CREATE, CALLBACK_REGION_INVALIDATE, CALLBACK_UPDATE };
final int[] r2ExpectedArgs = new int[] { 1, 9, 11, 13, 15, 17, 29 };
final int[] r2ExpectedTypes = new int[] { CALLBACK_CREATE, CALLBACK_UPDATE, CALLBACK_CREATE, CALLBACK_UPDATE, CALLBACK_DESTROY, CALLBACK_CREATE, CALLBACK_UPDATE };
// send notify to vm0
LogWriterUtils.getLogWriter().info("[doTestMultipleRegionConflation] wake up vm0");
getOtherVm().invoke(new SerializableRunnable("Wake up other vm") {
public void run() {
synchronized (doTestMultipleRegionConflation_R1_Listener.CONTROL_LOCK) {
doTestMultipleRegionConflation_R1_Listener.CONTROL_LOCK.notifyAll();
}
}
});
// wait for queue to be flushed
LogWriterUtils.getLogWriter().info("[doTestMultipleRegionConflation] wait for vm0");
getOtherVm().invoke(new SerializableRunnable("Wait for other vm") {
public void run() {
try {
synchronized (doTestMultipleRegionConflation_R1_Listener.CONTROL_LOCK) {
while (doTestMultipleRegionConflation_R1_Listener.callbackArguments.size() < r1ExpectedArgs.length) {
doTestMultipleRegionConflation_R1_Listener.CONTROL_LOCK.wait(millisToWait);
}
}
synchronized (doTestMultipleRegionConflation_R2_Listener.CONTROL_LOCK) {
while (doTestMultipleRegionConflation_R2_Listener.callbackArguments.size() < r2ExpectedArgs.length) {
doTestMultipleRegionConflation_R2_Listener.CONTROL_LOCK.wait(millisToWait);
}
}
} catch (InterruptedException ignore) {
fail("interrupted");
}
}
});
// assert values on both listeners
LogWriterUtils.getLogWriter().info("[doTestMultipleRegionConflation] assert callback arguments");
getOtherVm().invoke(new SerializableRunnable("Assert callback arguments") {
public void run() {
synchronized (doTestMultipleRegionConflation_R1_Listener.CONTROL_LOCK) {
LogWriterUtils.getLogWriter().info("doTestMultipleRegionConflation_R1_Listener.callbackArguments=" + doTestMultipleRegionConflation_R1_Listener.callbackArguments);
LogWriterUtils.getLogWriter().info("doTestMultipleRegionConflation_R1_Listener.callbackTypes=" + doTestMultipleRegionConflation_R1_Listener.callbackTypes);
assertEquals(doTestMultipleRegionConflation_R1_Listener.callbackArguments.size(), doTestMultipleRegionConflation_R1_Listener.callbackTypes.size());
int i = 0;
for (Iterator iter = doTestMultipleRegionConflation_R1_Listener.callbackArguments.iterator(); iter.hasNext(); ) {
CallbackWrapper wrapper = (CallbackWrapper) iter.next();
assertEquals(new Integer(r1ExpectedArgs[i]), wrapper.callbackArgument);
assertEquals(new Integer(r1ExpectedTypes[i]), doTestMultipleRegionConflation_R1_Listener.callbackTypes.get(i));
i++;
}
}
synchronized (doTestMultipleRegionConflation_R2_Listener.CONTROL_LOCK) {
LogWriterUtils.getLogWriter().info("doTestMultipleRegionConflation_R2_Listener.callbackArguments=" + doTestMultipleRegionConflation_R2_Listener.callbackArguments);
LogWriterUtils.getLogWriter().info("doTestMultipleRegionConflation_R2_Listener.callbackTypes=" + doTestMultipleRegionConflation_R2_Listener.callbackTypes);
assertEquals(doTestMultipleRegionConflation_R2_Listener.callbackArguments.size(), doTestMultipleRegionConflation_R2_Listener.callbackTypes.size());
int i = 0;
for (Iterator iter = doTestMultipleRegionConflation_R2_Listener.callbackArguments.iterator(); iter.hasNext(); ) {
CallbackWrapper wrapper = (CallbackWrapper) iter.next();
assertEquals(new Integer(r2ExpectedArgs[i]), wrapper.callbackArgument);
assertEquals(new Integer(r2ExpectedTypes[i]), doTestMultipleRegionConflation_R2_Listener.callbackTypes.get(i));
i++;
}
}
}
});
}
use of org.apache.geode.distributed.internal.DMStats in project geode by apache.
the class PdxInstanceImpl method basicGetObject.
@Override
protected synchronized Object basicGetObject() {
DMStats stats = InternalDataSerializer.getDMStats(null);
long start = stats.startPdxInstanceDeserialization();
try {
return super.basicGetObject();
} finally {
stats.endPdxInstanceDeserialization(start);
}
}
Aggregations