Search in sources :

Example 1 with DMStats

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

the class SlowRecDUnitTest method doTestPartialMessage.

private void doTestPartialMessage() throws Exception {
    final AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_NO_ACK);
    factory.setEnableAsyncConflation(true);
    final Region r = createRootRegion("slowrec", factory.create());
    final DM dm = getSystem().getDistributionManager();
    final DMStats stats = dm.getStats();
    // set others before vm0 connects
    long initialQueuedMsgs = stats.getAsyncQueuedMsgs();
    // create receiver in vm0 with queuing enabled
    final Properties p = new Properties();
    // 4 sec
    p.setProperty(ASYNC_DISTRIBUTION_TIMEOUT, String.valueOf(1000 * 4));
    // 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);
            doTestPartialMessage_Listener = new ControlListener();
            af.setCacheListener(doTestPartialMessage_Listener);
            createRootRegion("slowrec", af.create());
        }
    });
    // put vm0 cache listener into wait
    LogWriterUtils.getLogWriter().info("[testPartialMessage] about to put vm0 into wait");
    // 5 minutes
    final int millisToWait = 1000 * 60 * 5;
    r.put(KEY_WAIT, new Integer(millisToWait));
    // build up queue size
    LogWriterUtils.getLogWriter().info("[testPartialMessage] building up queue size...");
    final Object key = "key";
    final int socketBufferSize = getSystem().getConfig().getSocketBufferSize();
    final int VALUE_SIZE = socketBufferSize * 3;
    // 1024 * 20; // 20 KB
    final byte[] value = new byte[VALUE_SIZE];
    int count = 0;
    while (stats.getAsyncQueuedMsgs() == initialQueuedMsgs) {
        count++;
        r.put(key, value, new Integer(count));
    }
    final int partialId = count;
    assertEquals(0, stats.getAsyncConflatedMsgs());
    LogWriterUtils.getLogWriter().info("[testPartialMessage] After " + count + " puts of size " + VALUE_SIZE + " slowrec mode kicked in with queue size=" + stats.getAsyncQueueSize());
    Wait.pause(2000);
    // conflate 10 times
    while (stats.getAsyncConflatedMsgs() < 10) {
        count++;
        r.put(key, value, new Integer(count));
        if (count == partialId + 1) {
            assertEquals(initialQueuedMsgs + 2, stats.getAsyncQueuedMsgs());
            assertEquals(0, stats.getAsyncConflatedMsgs());
        } else if (count == partialId + 2) {
            assertEquals(initialQueuedMsgs + 2, stats.getAsyncQueuedMsgs());
            assertEquals(1, stats.getAsyncConflatedMsgs());
        }
    }
    final int conflateId = count;
    final int[] expectedArgs = { partialId, conflateId };
    // send notify to vm0
    LogWriterUtils.getLogWriter().info("[testPartialMessage] wake up vm0");
    getOtherVm().invoke(new SerializableRunnable("Wake up other vm") {

        public void run() {
            synchronized (doTestPartialMessage_Listener.CONTROL_LOCK) {
                doTestPartialMessage_Listener.CONTROL_LOCK.notify();
            }
        }
    });
    // wait for queue to be flushed
    LogWriterUtils.getLogWriter().info("[testPartialMessage] wait for vm0");
    getOtherVm().invoke(new SerializableRunnable("Wait for other vm") {

        public void run() {
            try {
                synchronized (doTestPartialMessage_Listener.CONTROL_LOCK) {
                    boolean done = false;
                    while (!done) {
                        if (doTestPartialMessage_Listener.callbackArguments.size() > 0) {
                            CallbackWrapper last = (CallbackWrapper) doTestPartialMessage_Listener.callbackArguments.getLast();
                            Integer lastId = (Integer) last.callbackArgument;
                            if (lastId.intValue() == conflateId) {
                                done = true;
                            } else {
                                doTestPartialMessage_Listener.CONTROL_LOCK.wait(millisToWait);
                            }
                        } else {
                            doTestPartialMessage_Listener.CONTROL_LOCK.wait(millisToWait);
                        }
                    }
                }
            } catch (InterruptedException ignore) {
                fail("interrupted");
            }
        }
    });
    // assert values on both listeners
    LogWriterUtils.getLogWriter().info("[testPartialMessage] assert callback arguments");
    getOtherVm().invoke(new SerializableRunnable("Assert callback arguments") {

        public void run() {
            synchronized (doTestPartialMessage_Listener.CONTROL_LOCK) {
                LogWriterUtils.getLogWriter().info("[testPartialMessage] " + "doTestPartialMessage_Listener.callbackArguments=" + doTestPartialMessage_Listener.callbackArguments);
                assertEquals(doTestPartialMessage_Listener.callbackArguments.size(), doTestPartialMessage_Listener.callbackTypes.size());
                int i = 0;
                Iterator argIter = doTestPartialMessage_Listener.callbackArguments.iterator();
                Iterator typeIter = doTestPartialMessage_Listener.callbackTypes.iterator();
                while (argIter.hasNext()) {
                    CallbackWrapper wrapper = (CallbackWrapper) argIter.next();
                    Integer arg = (Integer) wrapper.callbackArgument;
                    // Integer type
                    typeIter.next();
                    if (arg.intValue() < partialId) {
                        continue;
                    }
                    assertEquals(new Integer(expectedArgs[i]), arg);
                    // assertIndexDetailsEquals(CALLBACK_UPDATE_INTEGER, type);
                    i++;
                }
            }
        }
    });
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) 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) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region)

Example 2 with DMStats

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

the class SlowRecDUnitTest method forceQueuing.

private void forceQueuing(final Region r) throws CacheException {
    Connection.FORCE_ASYNC_QUEUE = true;
    final DMStats stats = getSystem().getDistributionManager().getStats();
    r.put("forcekey", "forcevalue");
    // wait for the flusher to get its first flush in progress
    WaitCriterion ev = new WaitCriterion() {

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

        public String description() {
            return "waiting for flushes to start";
        }
    };
    Wait.waitForCriterion(ev, 2 * 1000, 200, true);
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion)

Example 3 with DMStats

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

the class SlowRecDUnitTest method testTimeoutDisconnect.

/**
   * Make sure that exceeding the async-queue-timeout causes a disconnect.
   * <p>
   * [bruce] This test was disabled when the SlowRecDUnitTest was re-enabled in build.xml in the
   * splitbrainNov07 branch. It had been disabled since June 2006 due to hangs. Some of the tests,
   * like this one, still need work because the periodically (some quite often) fail.
   */
@Test
public void testTimeoutDisconnect() throws Exception {
    final String expected = "org.apache.geode.internal.tcp.ConnectionException: Forced disconnect sent to" + "||java.io.IOException: Broken pipe";
    final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
    final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
    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();
    // create receiver in vm0 with queuing enabled
    Properties p = new Properties();
    p.setProperty(ASYNC_DISTRIBUTION_TIMEOUT, "5");
    // 500 ms
    p.setProperty(ASYNC_QUEUE_TIMEOUT, "500");
    doCreateOtherVm(p, true);
    final Object key = "key";
    // 1k
    final int VALUE_SIZE = 1024;
    final byte[] value = new byte[VALUE_SIZE];
    int count = 0;
    long queuedMsgs = stats.getAsyncQueuedMsgs();
    long queueSize = stats.getAsyncQueueSize();
    final long timeoutLimit = System.currentTimeMillis() + 5000;
    getCache().getLogger().info(addExpected);
    try {
        while (stats.getAsyncQueueTimeouts() == 0) {
            r.put(key, value);
            count++;
            if (stats.getAsyncQueueSize() > 0) {
                queuedMsgs = stats.getAsyncQueuedMsgs();
                queueSize = stats.getAsyncQueueSize();
            }
            if (System.currentTimeMillis() > timeoutLimit) {
                fail("should have exceeded async-queue-timeout by now");
            }
        }
        LogWriterUtils.getLogWriter().info("After " + count + " " + VALUE_SIZE + " byte puts slowrec mode kicked in but the queue filled when its size reached " + queueSize + " with " + queuedMsgs + " msgs");
        // make sure we lost a connection to vm0
        WaitCriterion ev = new WaitCriterion() {

            public boolean done() {
                if (dm.getOtherDistributionManagerIds().size() > others.size()) {
                    return false;
                }
                return stats.getAsyncQueueSize() == 0;
            }

            public String description() {
                return "waiting for departure";
            }
        };
        Wait.waitForCriterion(ev, 2 * 1000, 200, true);
    } finally {
        getCache().getLogger().info(removeExpected);
    }
    assertEquals(others, dm.getOtherDistributionManagerIds());
    assertEquals(0, stats.getAsyncQueueSize());
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) AttributesFactory(org.apache.geode.cache.AttributesFactory) Set(java.util.Set) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Region(org.apache.geode.cache.Region) DM(org.apache.geode.distributed.internal.DM) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 4 with DMStats

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

the class SlowRecDUnitTest method testSizeDisconnect.

/**
   * Make sure that exceeding the queue size limit causes a disconnect.
   */
@Test
public void testSizeDisconnect() throws Exception {
    final String expected = "org.apache.geode.internal.tcp.ConnectionException: Forced disconnect sent to" + "||java.io.IOException: Broken pipe";
    final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
    final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
    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();
    // create receiver in vm0 with queuing enabled
    Properties p = new Properties();
    p.setProperty(ASYNC_DISTRIBUTION_TIMEOUT, "5");
    // 1 meg
    p.setProperty(ASYNC_MAX_QUEUE_SIZE, "1");
    doCreateOtherVm(p, false);
    final Object key = "key";
    // .1M async-max-queue-size should give us 10 of these 100K
    final int VALUE_SIZE = 1024 * 100;
    // msgs before queue full
    final byte[] value = new byte[VALUE_SIZE];
    int count = 0;
    forceQueuing(r);
    long queuedMsgs = stats.getAsyncQueuedMsgs();
    long queueSize = stats.getAsyncQueueSize();
    getCache().getLogger().info(addExpected);
    try {
        while (stats.getAsyncQueueSizeExceeded() == 0 && stats.getAsyncQueueTimeouts() == 0) {
            r.put(key, value);
            count++;
            if (stats.getAsyncQueueSize() > 0) {
                queuedMsgs = stats.getAsyncQueuedMsgs();
                queueSize = stats.getAsyncQueueSize();
            }
            if (count > 100) {
                fail("should have exceeded max-queue-size by now");
            }
        }
        LogWriterUtils.getLogWriter().info("After " + count + " " + VALUE_SIZE + " byte puts slowrec mode kicked in but the queue filled when its size reached " + queueSize + " with " + queuedMsgs + " msgs");
        // make sure we lost a connection to vm0
        WaitCriterion ev = new WaitCriterion() {

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

            public String description() {
                return "waiting for connection loss";
            }
        };
        Wait.waitForCriterion(ev, 30 * 1000, 200, true);
    } finally {
        forceQueueFlush();
        getCache().getLogger().info(removeExpected);
    }
    assertEquals(others, dm.getOtherDistributionManagerIds());
    assertEquals(0, stats.getAsyncQueueSize());
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) AttributesFactory(org.apache.geode.cache.AttributesFactory) Set(java.util.Set) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Region(org.apache.geode.cache.Region) DM(org.apache.geode.distributed.internal.DM) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 5 with DMStats

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

the class GMSMembershipManagerJUnitTest method testReplyProcessorInitiatesSuspicion.

@Test
public void testReplyProcessorInitiatesSuspicion() throws Exception {
    DM dm = mock(DM.class);
    DMStats stats = mock(DMStats.class);
    InternalDistributedSystem system = InternalDistributedSystem.newInstanceForTesting(dm, distProperties);
    when(dm.getStats()).thenReturn(stats);
    when(dm.getSystem()).thenReturn(system);
    when(dm.getCancelCriterion()).thenReturn(stopper);
    when(dm.getMembershipManager()).thenReturn(manager);
    when(dm.getViewMembers()).thenReturn(members);
    when(dm.getDistributionManagerIds()).thenReturn(new HashSet(members));
    when(dm.addMembershipListenerAndGetDistributionManagerIds(any(MembershipListener.class))).thenReturn(new HashSet(members));
    manager.start();
    manager.started();
    manager.isJoining = true;
    List<InternalDistributedMember> viewmembers = Arrays.asList(new InternalDistributedMember[] { mockMembers[0], mockMembers[1], myMemberId });
    manager.installView(new NetView(myMemberId, 2, viewmembers));
    List<InternalDistributedMember> mbrs = new ArrayList<>(1);
    mbrs.add(mockMembers[0]);
    ReplyProcessor21 rp = new ReplyProcessor21(dm, mbrs);
    rp.enableSevereAlertProcessing();
    boolean result = rp.waitForReplies(WAIT_FOR_REPLIES_MILLIS);
    // the wait should have timed out
    assertFalse(result);
    verify(healthMonitor, atLeastOnce()).checkIfAvailable(isA(InternalDistributedMember.class), isA(String.class), isA(Boolean.class));
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) NetView(org.apache.geode.distributed.internal.membership.NetView) ArrayList(java.util.ArrayList) DM(org.apache.geode.distributed.internal.DM) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedMembershipListener(org.apache.geode.distributed.internal.membership.DistributedMembershipListener) MembershipListener(org.apache.geode.distributed.internal.MembershipListener) HashSet(java.util.HashSet) ReplyProcessor21(org.apache.geode.distributed.internal.ReplyProcessor21) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

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