Search in sources :

Example 21 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class ProxyDUnitTest method remoteOriginOps.

/**
   * check remote ops done in a normal vm are correctly distributed to PROXY regions
   */
private void remoteOriginOps(DataPolicy dp, InterestPolicy ip) throws CacheException {
    initOtherId();
    AttributesFactory af = new AttributesFactory();
    af.setDataPolicy(dp);
    af.setSubscriptionAttributes(new SubscriptionAttributes(ip));
    af.setScope(Scope.DISTRIBUTED_ACK);
    CacheListener cl1 = new CacheListener() {

        public void afterUpdate(EntryEvent e) {
            clLastEvent = e;
            clInvokeCount++;
        }

        public void afterCreate(EntryEvent e) {
            clLastEvent = e;
            clInvokeCount++;
        }

        public void afterInvalidate(EntryEvent e) {
            clLastEvent = e;
            clInvokeCount++;
        }

        public void afterDestroy(EntryEvent e) {
            clLastEvent = e;
            clInvokeCount++;
        }

        public void afterRegionInvalidate(RegionEvent e) {
            clLastEvent = e;
            clInvokeCount++;
        }

        public void afterRegionDestroy(RegionEvent e) {
            clLastEvent = e;
            clInvokeCount++;
        }

        public void afterRegionClear(RegionEvent e) {
            clLastEvent = e;
            clInvokeCount++;
        }

        public void afterRegionCreate(RegionEvent e) {
        }

        public void afterRegionLive(RegionEvent e) {
        }

        public void close() {
        }
    };
    af.addCacheListener(cl1);
    Region r = createRootRegion("ProxyDUnitTest", af.create());
    this.clInvokeCount = 0;
    doCreateOtherVm();
    DMStats stats = getDMStats();
    long receivedMsgs = stats.getReceivedMessages();
    if (ip.isAll()) {
        getOtherVm().invoke(new CacheSerializableRunnable("do put") {

            public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                r.put("p", "v");
            }
        });
        assertEquals(1, this.clInvokeCount);
        assertEquals(Operation.CREATE, this.clLastEvent.getOperation());
        assertEquals(true, this.clLastEvent.isOriginRemote());
        assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
        assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
        // failure
        assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable());
        assertEquals("v", ((EntryEvent) this.clLastEvent).getNewValue());
        assertEquals("p", ((EntryEvent) this.clLastEvent).getKey());
        this.clInvokeCount = 0;
        getOtherVm().invoke(new CacheSerializableRunnable("do create") {

            public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                r.create("c", "v");
            }
        });
        assertEquals(1, this.clInvokeCount);
        assertEquals(Operation.CREATE, this.clLastEvent.getOperation());
        assertEquals(true, this.clLastEvent.isOriginRemote());
        assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
        assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
        assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable());
        assertEquals("v", ((EntryEvent) this.clLastEvent).getNewValue());
        assertEquals("c", ((EntryEvent) this.clLastEvent).getKey());
        this.clInvokeCount = 0;
        getOtherVm().invoke(new CacheSerializableRunnable("do update") {

            public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                r.put("c", "v2");
            }
        });
        assertEquals(1, this.clInvokeCount);
        assertEquals(Operation.UPDATE, this.clLastEvent.getOperation());
        assertEquals(true, this.clLastEvent.isOriginRemote());
        assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
        assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
        assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable());
        assertEquals("v2", ((EntryEvent) this.clLastEvent).getNewValue());
        assertEquals("c", ((EntryEvent) this.clLastEvent).getKey());
        this.clInvokeCount = 0;
        getOtherVm().invoke(new CacheSerializableRunnable("do invalidate") {

            public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                r.invalidate("c");
            }
        });
        assertEquals(1, this.clInvokeCount);
        assertEquals(Operation.INVALIDATE, this.clLastEvent.getOperation());
        assertEquals(true, this.clLastEvent.isOriginRemote());
        assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
        assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
        assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable());
        assertEquals(null, ((EntryEvent) this.clLastEvent).getNewValue());
        assertEquals("c", ((EntryEvent) this.clLastEvent).getKey());
        this.clInvokeCount = 0;
        getOtherVm().invoke(new CacheSerializableRunnable("do destroy") {

            public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                r.destroy("c");
            }
        });
        assertEquals(1, this.clInvokeCount);
        assertEquals(Operation.DESTROY, this.clLastEvent.getOperation());
        assertEquals(true, this.clLastEvent.isOriginRemote());
        assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
        assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
        assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable());
        assertEquals(null, ((EntryEvent) this.clLastEvent).getNewValue());
        assertEquals("c", ((EntryEvent) this.clLastEvent).getKey());
        this.clInvokeCount = 0;
        getOtherVm().invoke(new CacheSerializableRunnable("do putAll") {

            public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                Map m = new HashMap();
                m.put("putAllKey1", "putAllValue1");
                m.put("putAllKey2", "putAllValue2");
                r.putAll(m);
            }
        });
        assertEquals(2, this.clInvokeCount);
        // @todo darrel; check putAll events
        this.clInvokeCount = 0;
        getOtherVm().invoke(new CacheSerializableRunnable("do netsearch") {

            public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                // total miss
                assertEquals(null, r.get("loadkey"));
            }
        });
        assertEquals(0, this.clInvokeCount);
    } else {
        getOtherVm().invoke(new CacheSerializableRunnable("do entry ops") {

            public void run2() throws CacheException {
                Region r = getRootRegion("ProxyDUnitTest");
                r.put("p", "v");
                r.create("c", "v");
                // update
                r.put("c", "v");
                r.invalidate("c");
                r.destroy("c");
                {
                    Map m = new HashMap();
                    m.put("putAllKey1", "putAllValue1");
                    m.put("putAllKey2", "putAllValue2");
                    r.putAll(m);
                }
                // total miss
                assertEquals(null, r.get("loadkey"));
            }
        });
        assertEquals(0, this.clInvokeCount);
        assertEquals(0, r.size());
        // check the stats to make sure none of the above sent up messages
        assertEquals(receivedMsgs, stats.getReceivedMessages());
    }
    {
        AttributesMutator am = r.getAttributesMutator();
        CacheLoader cl = new CacheLoader() {

            public Object load(LoaderHelper helper) throws CacheLoaderException {
                if (helper.getKey().equals("loadkey")) {
                    return "loadvalue";
                } else if (helper.getKey().equals("loadexception")) {
                    throw new CacheLoaderException("expected");
                } else {
                    return null;
                }
            }

            public void close() {
            }
        };
        am.setCacheLoader(cl);
    }
    receivedMsgs = stats.getReceivedMessages();
    getOtherVm().invoke(new CacheSerializableRunnable("check net loader") {

        public void run2() throws CacheException {
            Region r = getRootRegion("ProxyDUnitTest");
            // net load
            assertEquals("loadvalue", r.get("loadkey"));
            // total miss
            assertEquals(null, r.get("foobar"));
            try {
                r.get("loadexception");
                fail("expected CacheLoaderException");
            } catch (CacheLoaderException expected) {
            }
        }
    });
    assertTrue(stats.getReceivedMessages() > receivedMsgs);
    if (ip.isAll()) {
        assertEquals(1, this.clInvokeCount);
        assertEquals(Operation.NET_LOAD_CREATE, this.clLastEvent.getOperation());
        assertEquals(true, this.clLastEvent.isOriginRemote());
        assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
        assertEquals(null, ((EntryEvent) this.clLastEvent).getOldValue());
        assertEquals(false, ((EntryEvent) this.clLastEvent).isOldValueAvailable());
        this.clInvokeCount = 0;
    } else {
        assertEquals(0, this.clInvokeCount);
    }
    {
        AttributesMutator am = r.getAttributesMutator();
        am.setCacheLoader(null);
        CacheWriter cw = new CacheWriterAdapter() {

            public void beforeCreate(EntryEvent event) throws CacheWriterException {
                throw new CacheWriterException("expected");
            }
        };
        am.setCacheWriter(cw);
    }
    receivedMsgs = stats.getReceivedMessages();
    getOtherVm().invoke(new CacheSerializableRunnable("check net write") {

        public void run2() throws CacheException {
            Region r = getRootRegion("ProxyDUnitTest");
            try {
                r.put("putkey", "putvalue");
                fail("expected CacheWriterException");
            } catch (CacheWriterException expected) {
            }
        }
    });
    assertTrue(stats.getReceivedMessages() > receivedMsgs);
    {
        AttributesMutator am = r.getAttributesMutator();
        am.setCacheWriter(null);
    }
    assertEquals(0, this.clInvokeCount);
    this.clLastEvent = null;
    getOtherVm().invoke(new CacheSerializableRunnable("check region invalidate") {

        public void run2() throws CacheException {
            Region r = getRootRegion("ProxyDUnitTest");
            r.invalidateRegion();
        }
    });
    assertEquals(1, this.clInvokeCount);
    assertEquals(Operation.REGION_INVALIDATE, this.clLastEvent.getOperation());
    assertEquals(true, this.clLastEvent.isOriginRemote());
    assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
    this.clLastEvent = null;
    getOtherVm().invoke(new CacheSerializableRunnable("check region clear") {

        public void run2() throws CacheException {
            Region r = getRootRegion("ProxyDUnitTest");
            r.clear();
        }
    });
    assertEquals(2, this.clInvokeCount);
    assertEquals(Operation.REGION_CLEAR, this.clLastEvent.getOperation());
    assertEquals(true, this.clLastEvent.isOriginRemote());
    assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
    this.clLastEvent = null;
    getOtherVm().invoke(new CacheSerializableRunnable("check region destroy") {

        public void run2() throws CacheException {
            Region r = getRootRegion("ProxyDUnitTest");
            r.destroyRegion();
        }
    });
    assertEquals(3, this.clInvokeCount);
    assertEquals(Operation.REGION_DESTROY, this.clLastEvent.getOperation());
    assertEquals(true, this.clLastEvent.isOriginRemote());
    assertEquals(this.otherId, this.clLastEvent.getDistributedMember());
    assertTrue(r.isDestroyed());
}
Also used : CacheWriterAdapter(org.apache.geode.cache.util.CacheWriterAdapter) DMStats(org.apache.geode.distributed.internal.DMStats) CacheException(org.apache.geode.cache.CacheException) HashMap(java.util.HashMap) RegionEvent(org.apache.geode.cache.RegionEvent) CacheListener(org.apache.geode.cache.CacheListener) LoaderHelper(org.apache.geode.cache.LoaderHelper) AttributesFactory(org.apache.geode.cache.AttributesFactory) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) EntryEvent(org.apache.geode.cache.EntryEvent) CacheWriter(org.apache.geode.cache.CacheWriter) Region(org.apache.geode.cache.Region) CacheLoader(org.apache.geode.cache.CacheLoader) HashMap(java.util.HashMap) Map(java.util.Map) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes) AttributesMutator(org.apache.geode.cache.AttributesMutator) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 22 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class SlowRecDUnitTest method forceQueueFlush.

private void forceQueueFlush() {
    Connection.FORCE_ASYNC_QUEUE = false;
    final DMStats stats = getSystem().getDistributionManager().getStats();
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return stats.getAsyncThreads() == 0;
        }

        public String description() {
            return "Waiting for async threads to disappear";
        }
    };
    Wait.waitForCriterion(ev, 10 * 1000, 200, true);
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion)

Example 23 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class SlowRecDUnitTest method testConflationSequence.

/**
   * Make sure that only sequences of updates are conflated Also checks that sending to a conflating
   * region and non-conflating region does the correct thing. Test disabled because it
   * intermittently fails due to race conditions in test. This has been fixed in congo's tests. See
   * bug 35357.
   */
@Test
public void testConflationSequence() throws Exception {
    final AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_NO_ACK);
    factory.setEnableAsyncConflation(true);
    final Region r = createRootRegion("slowrec", factory.create());
    factory.setEnableAsyncConflation(false);
    final Region noConflate = createRootRegion("noConflate", 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);
    {
        VM vm = getOtherVm();
        vm.invoke(new CacheSerializableRunnable("create noConflate") {

            public void run2() throws CacheException {
                AttributesFactory af = new AttributesFactory();
                af.setScope(Scope.DISTRIBUTED_NO_ACK);
                af.setDataPolicy(DataPolicy.REPLICATE);
                createRootRegion("noConflate", af.create());
            }
        });
    }
    // now make sure update+destroy does not conflate
    final Object key = "key";
    LogWriterUtils.getLogWriter().info("[testConflationSequence] about to force queuing");
    forceQueuing(r);
    int count = 0;
    String value = "";
    String lastValue = value;
    Object mylcb = null;
    long initialConflatedMsgs = stats.getAsyncConflatedMsgs();
    int endCount = count + 60;
    LogWriterUtils.getLogWriter().info("[testConflationSequence] about to build up queue");
    long begin = System.currentTimeMillis();
    while (count < endCount) {
        value = "count=" + count;
        lastValue = value;
        r.create(key, value);
        count++;
        value = "count=" + count;
        lastValue = value;
        r.put(key, value);
        count++;
        mylcb = value;
        r.destroy(key, mylcb);
        count++;
        lastValue = null;
        assertTrue(System.currentTimeMillis() < begin + 1000 * 60 * 2);
    }
    assertEquals(initialConflatedMsgs, stats.getAsyncConflatedMsgs());
    forceQueueFlush();
    checkLastValueInOtherVm(lastValue, mylcb);
    // now make sure create+update+localDestroy does not conflate
    LogWriterUtils.getLogWriter().info("[testConflationSequence] force queuing create-update-destroy");
    forceQueuing(r);
    initialConflatedMsgs = stats.getAsyncConflatedMsgs();
    endCount = count + 40;
    LogWriterUtils.getLogWriter().info("[testConflationSequence] create-update-destroy");
    begin = System.currentTimeMillis();
    while (count < endCount) {
        value = "count=" + count;
        lastValue = value;
        r.create(key, value);
        count++;
        value = "count=" + count;
        lastValue = value;
        r.put(key, value);
        count++;
        r.localDestroy(key);
        assertTrue(System.currentTimeMillis() < begin + 1000 * 60 * 2);
    }
    assertEquals(initialConflatedMsgs, stats.getAsyncConflatedMsgs());
    forceQueueFlush();
    checkLastValueInOtherVm(lastValue, null);
    // now make sure update+invalidate does not conflate
    LogWriterUtils.getLogWriter().info("[testConflationSequence] force queuing update-invalidate");
    forceQueuing(r);
    initialConflatedMsgs = stats.getAsyncConflatedMsgs();
    value = "count=" + count;
    lastValue = value;
    r.create(key, value);
    count++;
    endCount = count + 40;
    LogWriterUtils.getLogWriter().info("[testConflationSequence] update-invalidate");
    begin = System.currentTimeMillis();
    while (count < endCount) {
        value = "count=" + count;
        lastValue = value;
        r.put(key, value);
        count++;
        r.invalidate(key);
        count++;
        lastValue = CHECK_INVALID;
        assertTrue(System.currentTimeMillis() < begin + 1000 * 60 * 2);
    }
    assertEquals(initialConflatedMsgs, stats.getAsyncConflatedMsgs());
    forceQueueFlush();
    LogWriterUtils.getLogWriter().info("[testConflationSequence] assert other vm");
    checkLastValueInOtherVm(lastValue, null);
    r.destroy(key);
    // now make sure updates to a conflating region are conflated even while
    // updates to a non-conflating are not.
    LogWriterUtils.getLogWriter().info("[testConflationSequence] conflate & no-conflate regions");
    forceQueuing(r);
    final int initialAsyncSocketWrites = stats.getAsyncSocketWrites();
    value = "count=" + count;
    lastValue = value;
    long conflatedMsgs = stats.getAsyncConflatedMsgs();
    long queuedMsgs = stats.getAsyncQueuedMsgs();
    r.create(key, value);
    queuedMsgs++;
    assertEquals(queuedMsgs, stats.getAsyncQueuedMsgs());
    assertEquals(conflatedMsgs, stats.getAsyncConflatedMsgs());
    r.put(key, value);
    queuedMsgs++;
    assertEquals(queuedMsgs, stats.getAsyncQueuedMsgs());
    assertEquals(conflatedMsgs, stats.getAsyncConflatedMsgs());
    noConflate.create(key, value);
    queuedMsgs++;
    assertEquals(queuedMsgs, stats.getAsyncQueuedMsgs());
    assertEquals(conflatedMsgs, stats.getAsyncConflatedMsgs());
    noConflate.put(key, value);
    queuedMsgs++;
    assertEquals(queuedMsgs, stats.getAsyncQueuedMsgs());
    assertEquals(conflatedMsgs, stats.getAsyncConflatedMsgs());
    count++;
    endCount = count + 80;
    begin = System.currentTimeMillis();
    LogWriterUtils.getLogWriter().info("[testConflationSequence:DEBUG] count=" + count + " queuedMsgs=" + stats.getAsyncQueuedMsgs() + " conflatedMsgs=" + stats.getAsyncConflatedMsgs() + " dequeuedMsgs=" + stats.getAsyncDequeuedMsgs() + " asyncSocketWrites=" + stats.getAsyncSocketWrites());
    while (count < endCount) {
        // make sure we continue to have a flush in progress
        assertEquals(1, stats.getAsyncThreads());
        assertEquals(1, stats.getAsyncQueues());
        assertTrue(stats.getAsyncQueueFlushesInProgress() > 0);
        // make sure we are not completing any flushing while this loop is in progress
        assertEquals(initialAsyncSocketWrites, stats.getAsyncSocketWrites());
        value = "count=" + count;
        lastValue = value;
        r.put(key, value);
        count++;
        // make sure it was conflated and not queued
        assertEquals(queuedMsgs, stats.getAsyncQueuedMsgs());
        conflatedMsgs++;
        assertEquals(conflatedMsgs, stats.getAsyncConflatedMsgs());
        noConflate.put(key, value);
        // make sure it was queued and not conflated
        queuedMsgs++;
        assertEquals(queuedMsgs, stats.getAsyncQueuedMsgs());
        assertEquals(conflatedMsgs, stats.getAsyncConflatedMsgs());
        assertTrue(System.currentTimeMillis() < begin + 1000 * 60 * 2);
    }
    forceQueueFlush();
    LogWriterUtils.getLogWriter().info("[testConflationSequence] assert other vm");
    checkLastValueInOtherVm(lastValue, null);
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) AttributesFactory(org.apache.geode.cache.AttributesFactory) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 24 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class SlowRecDUnitTest method doTestDisconnectCleanup.

private void doTestDisconnectCleanup() throws Exception {
    final AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_NO_ACK);
    final Region r = createRootRegion("slowrec", factory.create());
    final DM dm = getSystem().getDistributionManager();
    final DMStats stats = dm.getStats();
    // set others before vm0 connects
    final Set others = dm.getOtherDistributionManagerIds();
    long initialQueuedMsgs = stats.getAsyncQueuedMsgs();
    final int initialQueues = stats.getAsyncQueues();
    // 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);
            AttributesFactory af = new AttributesFactory();
            af.setScope(Scope.DISTRIBUTED_NO_ACK);
            af.setDataPolicy(DataPolicy.REPLICATE);
            doTestDisconnectCleanup_Listener = new ControlListener();
            af.setCacheListener(doTestDisconnectCleanup_Listener);
            createRootRegion("slowrec", af.create());
        }
    });
    // put vm0 cache listener into wait
    LogWriterUtils.getLogWriter().info("[testDisconnectCleanup] about to put vm0 into wait");
    // 5 minutes
    int millisToWait = 1000 * 60 * 5;
    r.put(KEY_WAIT, new Integer(millisToWait));
    r.put(KEY_DISCONNECT, KEY_DISCONNECT);
    // build up queue size
    LogWriterUtils.getLogWriter().info("[testDisconnectCleanup] 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;
    final long abortMillis = System.currentTimeMillis() + millisToWait;
    while (stats.getAsyncQueuedMsgs() == initialQueuedMsgs) {
        count++;
        r.put(key, value);
        assertFalse(System.currentTimeMillis() >= abortMillis);
    }
    LogWriterUtils.getLogWriter().info("[testDisconnectCleanup] After " + count + " puts of size " + VALUE_SIZE + " slowrec mode kicked in with queue size=" + stats.getAsyncQueueSize());
    while (stats.getAsyncQueuedMsgs() < 10 || stats.getAsyncQueueSize() < VALUE_SIZE * 10) {
        count++;
        r.put(key, value);
        assertFalse(System.currentTimeMillis() >= abortMillis);
    }
    assertTrue(stats.getAsyncQueuedMsgs() >= 10);
    while (stats.getAsyncQueues() < 1) {
        Wait.pause(100);
        assertFalse(System.currentTimeMillis() >= abortMillis);
    }
    LogWriterUtils.getLogWriter().info("[testDisconnectCleanup] After " + count + " puts of size " + VALUE_SIZE + " queue size has reached " + stats.getAsyncQueueSize() + " bytes and number of queues is " + stats.getAsyncQueues() + ".");
    assertTrue(stats.getAsyncQueueSize() >= (VALUE_SIZE * 5));
    assertEquals(initialQueues + 1, stats.getAsyncQueues());
    // assert vm0 is still connected
    assertTrue(dm.getOtherDistributionManagerIds().size() > others.size());
    // send notify to vm0
    LogWriterUtils.getLogWriter().info("[testDisconnectCleanup] wake up vm0");
    getOtherVm().invoke(new SerializableRunnable("Wake up other vm") {

        public void run() {
            synchronized (doTestDisconnectCleanup_Listener.CONTROL_LOCK) {
                doTestDisconnectCleanup_Listener.CONTROL_LOCK.notifyAll();
            }
        }
    });
    // make sure we lost a connection to vm0
    LogWriterUtils.getLogWriter().info("[testDisconnectCleanup] wait for vm0 to disconnect");
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return dm.getOtherDistributionManagerIds().size() <= others.size();
        }

        public String description() {
            return "waiting for disconnect";
        }
    };
    Wait.waitForCriterion(ev, 2 * 1000, 200, true);
    assertEquals(others, dm.getOtherDistributionManagerIds());
    // check free memory... perform wait loop with System.gc
    LogWriterUtils.getLogWriter().info("[testDisconnectCleanup] wait for queue cleanup");
    ev = new WaitCriterion() {

        public boolean done() {
            if (stats.getAsyncQueues() <= initialQueues) {
                return true;
            }
            Runtime.getRuntime().gc();
            return false;
        }

        public String description() {
            return "waiting for queue cleanup";
        }
    };
    Wait.waitForCriterion(ev, 2 * 1000, 200, true);
    assertEquals(initialQueues, stats.getAsyncQueues());
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) Set(java.util.Set) CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) DM(org.apache.geode.distributed.internal.DM) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) AttributesFactory(org.apache.geode.cache.AttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Region(org.apache.geode.cache.Region)

Example 25 with DMStats

use of org.apache.geode.distributed.internal.DMStats in project geode by apache.

the class SlowRecDUnitTest method testNoAckConflation.

/**
   * Make sure that noack puts to a receiver will eventually queue and then catch up with conflation
   */
@Test
public void testNoAckConflation() throws Exception {
    final AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_NO_ACK);
    factory.setEnableAsyncConflation(true);
    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);
    forceQueuing(r);
    final Object key = "key";
    int count = 0;
    final long initialConflatedMsgs = stats.getAsyncConflatedMsgs();
    String lastValue = "";
    final long intialDeQueuedMsgs = stats.getAsyncDequeuedMsgs();
    long start = 0;
    try {
        while ((stats.getAsyncConflatedMsgs() - initialConflatedMsgs) < 1000) {
            String value = "count=" + count;
            lastValue = value;
            r.put(key, value);
            count++;
        }
        start = System.currentTimeMillis();
    } finally {
        forceQueueFlush();
    }
    final long finish = System.currentTimeMillis();
    LogWriterUtils.getLogWriter().info("After " + (finish - start) + " ms async msgs where flushed. A total of " + (stats.getAsyncDequeuedMsgs() - intialDeQueuedMsgs) + " were flushed. Leaving a queue size of " + stats.getAsyncQueueSize() + ". The lastValue was " + lastValue);
    checkLastValueInOtherVm(lastValue, null);
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) AttributesFactory(org.apache.geode.cache.AttributesFactory) Region(org.apache.geode.cache.Region) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

DMStats (org.apache.geode.distributed.internal.DMStats)29 Region (org.apache.geode.cache.Region)12 AttributesFactory (org.apache.geode.cache.AttributesFactory)10 Properties (java.util.Properties)9 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)9 Test (org.junit.Test)9 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)7 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)7 CacheException (org.apache.geode.cache.CacheException)6 DM (org.apache.geode.distributed.internal.DM)6 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 IOException (java.io.IOException)5 ByteBuffer (java.nio.ByteBuffer)5 Iterator (java.util.Iterator)3 Set (java.util.Set)3 IgnoredException (org.apache.geode.test.dunit.IgnoredException)3 VM (org.apache.geode.test.dunit.VM)3 InterruptedIOException (java.io.InterruptedIOException)2 ConnectException (java.net.ConnectException)2 SocketException (java.net.SocketException)2