Search in sources :

Example 1 with SizeableRunnable

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

the class DistributedSystemDUnitTest method testWaitForDeparture.

/**
   * ensure that waitForMemberDeparture correctly flushes the serial message queue for the given
   * member
   */
@Test
public void testWaitForDeparture() throws Exception {
    Properties config = new Properties();
    config.put(LOCATORS, "");
    config.put(START_LOCATOR, "localhost[" + this.locatorPort + "]");
    config.put(DISABLE_TCP, "true");
    InternalDistributedSystem system = (InternalDistributedSystem) DistributedSystem.connect(config);
    // construct a member ID that will represent a departed member
    InternalDistributedMember member = new InternalDistributedMember("localhost", 12345, "", "", NORMAL_DM_TYPE, null, null);
    // schedule a message in order to create a queue for the fake member
    DistributionManager distributionManager = (DistributionManager) system.getDistributionManager();
    final FakeMessage message = new FakeMessage(null);
    distributionManager.getExecutor(SERIAL_EXECUTOR, member).execute(new SizeableRunnable(100) {

        @Override
        public void run() {
            // always throws NullPointerException
            message.doAction(distributionManager, false);
        }

        @Override
        public String toString() {
            return "Processing fake message";
        }
    });
    Assert.assertTrue("expected the serial queue to be flushed", distributionManager.getMembershipManager().waitForDeparture(member));
    Assert.assertTrue(message.processed);
}
Also used : InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) SizeableRunnable(org.apache.geode.distributed.internal.SizeableRunnable) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 2 with SizeableRunnable

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

the class GMSMembershipManager method waitForSerialMessageProcessing.

/**
   * wait for serial executor messages from the given member to be processed
   */
public boolean waitForSerialMessageProcessing(InternalDistributedMember idm) throws InterruptedException {
    // run a message through the member's serial execution queue to ensure that all of its
    // current messages have been processed
    boolean result = false;
    OverflowQueueWithDMStats serialQueue = listener.getDM().getSerialQueue(idm);
    if (serialQueue != null) {
        final boolean[] done = new boolean[1];
        final FlushingMessage msg = new FlushingMessage(done);
        serialQueue.add(new SizeableRunnable(100) {

            public void run() {
                msg.invoke();
            }

            public String toString() {
                return "Processing fake message";
            }
        });
        synchronized (done) {
            while (!done[0]) {
                done.wait(10);
            }
            result = true;
        }
    }
    return result;
}
Also used : SizeableRunnable(org.apache.geode.distributed.internal.SizeableRunnable) OverflowQueueWithDMStats(org.apache.geode.distributed.internal.OverflowQueueWithDMStats)

Aggregations

SizeableRunnable (org.apache.geode.distributed.internal.SizeableRunnable)2 Properties (java.util.Properties)1 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)1 DistributionManager (org.apache.geode.distributed.internal.DistributionManager)1 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)1 OverflowQueueWithDMStats (org.apache.geode.distributed.internal.OverflowQueueWithDMStats)1 InternalDistributedMember (org.apache.geode.distributed.internal.membership.InternalDistributedMember)1 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)1 MembershipTest (org.apache.geode.test.junit.categories.MembershipTest)1 Test (org.junit.Test)1