Search in sources :

Example 51 with WaitCriterion

use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.

the class OperationsPropagationDUnitTest method assertRemoveAllSucceeded.

public static void assertRemoveAllSucceeded() {
    WaitCriterion wc = new WaitCriterion() {

        String excuse;

        public boolean done() {
            Object val = region.get(PUTALL_KEY);
            return !region.containsKey(PUTALL_KEY) && !region.containsKey(PUTALL_KEY2);
        }

        public String description() {
            return excuse;
        }
    };
    Wait.waitForCriterion(wc, 60 * 1000, 1000, true);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion)

Example 52 with WaitCriterion

use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.

the class ClientConflationDUnitTest method assertCounterSizes.

/**
   * assert the listener counters size are as expected
   *
   */
public static void assertCounterSizes(String conflation) {
    // we do 5 puts on each key, so:
    // for writer 1 default conflation is on
    final int create1 = 1;
    int update1 = 1;
    // for writer 2 default conflation is off
    final int create2 = 1;
    int update2 = 4;
    if (conflation.equals(DistributionConfig.CLIENT_CONFLATION_PROP_VALUE_ON)) {
        // override
        update2 = 1;
    } else if (conflation.equals(DistributionConfig.CLIENT_CONFLATION_PROP_VALUE_OFF)) {
        // override
        update1 = 4;
    }
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            // TODO is this necessary?
            Thread.yield();
            return counterCreate1 == create1;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 60 * 1000, 200, true);
    final int u1 = update1;
    ev = new WaitCriterion() {

        public boolean done() {
            // TODO is this necessary?
            Thread.yield();
            return counterUpdate1 == u1;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 60 * 1000, 200, true);
    ev = new WaitCriterion() {

        public boolean done() {
            // TODO is this necessary?
            Thread.yield();
            return counterCreate2 == create2;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 60 * 1000, 200, true);
    final int u2 = update2;
    ev = new WaitCriterion() {

        public boolean done() {
            // TODO is this necessary?
            Thread.yield();
            return counterUpdate2 == u2;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 60 * 1000, 200, true);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion)

Example 53 with WaitCriterion

use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.

the class ClientHealthMonitorJUnitTest method testDeadClientRemovalByServer.

/**
   * This test performs the following:<br>
   * 1)create server<br>
   * 2)initialize proxy object and create region for client<br>
   * 3)perform a PUT on client by acquiring Connection through proxy<br>
   * 4)stop server monitor threads in client to ensure that server treats this as dead client <br>
   * 5)wait for some time to allow server to clean up the dead client artifacts<br>
   * 6)again perform a PUT on client through same Connection and verify after the put that the
   * Connection object used was new one.
   */
@Test
public void testDeadClientRemovalByServer() throws Exception {
    PORT = createServer();
    createProxyAndRegionForClient();
    // String connection2String = null;
    StatisticsType st = this.system.findType("CacheServerStats");
    final Statistics s = this.system.findStatisticsByType(st)[0];
    assertEquals(0, s.getInt("currentClients"));
    assertEquals(0, s.getInt("currentClientConnections"));
    this.system.getLogWriter().info("beforeAcquireConnection clients=" + s.getInt("currentClients") + " cnxs=" + s.getInt("currentClientConnections"));
    Connection connection1 = proxy.acquireConnection();
    this.system.getLogWriter().info("afterAcquireConnection clients=" + s.getInt("currentClients") + " cnxs=" + s.getInt("currentClientConnections"));
    this.system.getLogWriter().info("acquired connection " + connection1);
    WaitCriterion ev = new WaitCriterion() {

        public boolean done() {
            return s.getInt("currentClients") != 0;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, 20 * 1000, 200, true);
    assertEquals(1, s.getInt("currentClients"));
    assertEquals(1, s.getInt("currentClientConnections"));
    // String connection1String = connection1.toString();
    ServerRegionProxy srp = new ServerRegionProxy("region1", proxy);
    srp.putOnForTestsOnly(connection1, "key-1", "value-1", new EventID(new byte[] { 1 }, 1, 1), null);
    this.system.getLogWriter().info("did put 1");
    // proxy.testfinalizeServerConnectionMonitor();
    ev = new WaitCriterion() {

        public boolean done() {
            return s.getInt("currentClients") == 0;
        }

        public String description() {
            return null;
        }
    };
    Wait.waitForCriterion(ev, TIME_BETWEEN_PINGS * 5, 200, true);
    {
        this.system.getLogWriter().info("currentClients=" + s.getInt("currentClients") + " currentClientConnections=" + s.getInt("currentClientConnections"));
        assertEquals(0, s.getInt("currentClients"));
        assertEquals(0, s.getInt("currentClientConnections"));
    }
    addExceptions();
    // the connection should now fail since the server timed it out
    try {
        srp.putOnForTestsOnly(connection1, "key-1", "fail", new EventID(new byte[] { 1 }, 1, 2), null);
        fail("expected EOF");
    } catch (ServerConnectivityException expected) {
    }
// The rest of this test no longer works.
// connection1.finalizeConnection();
// proxy.release();
// connection1 = proxy.acquireConnection();
// connection2String = connection1.toString();
// this.system.getLogWriter().info("connection is now " + connection2String);
// if (connection1String.equals(connection2String)) {
// fail("New connection object was not obtained");
// }
// connection1.putObject("region1", "key-1", "value-2", new EventID(new byte[] {1},1,3), null);
// this.system.getLogWriter().info("did put 2");
// assertIndexDetailsEquals(1, s.getInt("currentClients"));
// assertIndexDetailsEquals(1, s.getInt("currentClientConnections"));
// // now lets see what happens when we close our connection
// // note we use a nasty close which just closes the socket instead
// // of sending a nice message to the server telling him we are going away
// ((ConnectionImpl)connection1).finalizeConnection();
// {
// int retry = (TIME_BETWEEN_PINGS*5) / 100;
// while (s.getInt("currentClients") > 0 && retry-- > 0) {
// Thread.sleep(100);
// }
// this.system.getLogWriter().info("currentClients="
// + s.getInt("currentClients")
// + " currentClientConnections="
// + s.getInt("currentClientConnections"));
// assertIndexDetailsEquals(0, s.getInt("currentClients"));
// assertIndexDetailsEquals(0, s.getInt("currentClientConnections"));
// }
}
Also used : ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) StatisticsType(org.apache.geode.StatisticsType) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection) EventID(org.apache.geode.internal.cache.EventID) Statistics(org.apache.geode.Statistics) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 54 with WaitCriterion

use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.

the class ClientServerMiscDUnitTest method verifyNoCacheClientProxyOnServer.

public static void verifyNoCacheClientProxyOnServer() {
    try {
        Cache cache = new ClientServerMiscDUnitTest().getCache();
        assertEquals("More than one BridgeServer", 1, cache.getCacheServers().size());
        CacheServerImpl bs = (CacheServerImpl) cache.getCacheServers().iterator().next();
        assertNotNull(bs);
        assertNotNull(bs.getAcceptor());
        final CacheClientNotifier ccn = bs.getAcceptor().getCacheClientNotifier();
        assertNotNull(ccn);
        WaitCriterion wc = new WaitCriterion() {

            String excuse;

            public boolean done() {
                return ccn.getClientProxies().size() == 0;
            }

            public String description() {
                return excuse;
            }
        };
        Wait.waitForCriterion(wc, 40 * 1000, 1000, true);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("while setting verifyNoCacheClientProxyOnServer  " + ex);
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) DistributedSystemDisconnectedException(org.apache.geode.distributed.DistributedSystemDisconnectedException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) GemFireIOException(org.apache.geode.GemFireIOException) GemFireConfigException(org.apache.geode.GemFireConfigException) CacheException(org.apache.geode.cache.CacheException) Cache(org.apache.geode.cache.Cache)

Example 55 with WaitCriterion

use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.

the class ClientServerMiscDUnitTest method verifyCacheClientProxyOnServer.

public static void verifyCacheClientProxyOnServer() {
    Cache cache = new ClientServerMiscDUnitTest().getCache();
    assertEquals("More than one BridgeServer", 1, cache.getCacheServers().size());
    CacheServerImpl bs = (CacheServerImpl) cache.getCacheServers().iterator().next();
    assertNotNull(bs);
    assertNotNull(bs.getAcceptor());
    final CacheClientNotifier ccn = bs.getAcceptor().getCacheClientNotifier();
    assertNotNull(ccn);
    WaitCriterion wc = new WaitCriterion() {

        String excuse;

        public boolean done() {
            return ccn.getClientProxies().size() == 1;
        }

        public String description() {
            return excuse;
        }
    };
    Wait.waitForCriterion(wc, 40 * 1000, 1000, true);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheServerImpl(org.apache.geode.internal.cache.CacheServerImpl) Cache(org.apache.geode.cache.Cache)

Aggregations

WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)368 Test (org.junit.Test)132 Region (org.apache.geode.cache.Region)105 VM (org.apache.geode.test.dunit.VM)96 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)93 Host (org.apache.geode.test.dunit.Host)73 LocalRegion (org.apache.geode.internal.cache.LocalRegion)58 CacheException (org.apache.geode.cache.CacheException)57 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)53 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)50 AttributesFactory (org.apache.geode.cache.AttributesFactory)41 IgnoredException (org.apache.geode.test.dunit.IgnoredException)40 IOException (java.io.IOException)36 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)36 Cache (org.apache.geode.cache.Cache)34 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)34 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)33 Properties (java.util.Properties)31 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)28 Iterator (java.util.Iterator)27