Search in sources :

Example 96 with WaitCriterion

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

the class InterestListEndpointDUnitTest method testInterestListEndpointAfterFailover.

@Test
public void testInterestListEndpointAfterFailover() throws Exception {
    final long maxWaitTime = 20000;
    client1.invoke(() -> createEntriesK1andK2());
    server2.invoke(() -> createEntriesK1andK2());
    server1.invoke(() -> createEntriesK1andK2());
    client1.invoke(() -> registerKey1());
    boolean firstIsPrimary = isVm0Primary();
    VM primary = firstIsPrimary ? server1 : server2;
    primary.invoke(() -> stopILEndpointServer());
    Wait.pause(5000);
    // Since the loadbalancing policy is roundrobin & there are two servers so
    // do two dumb puts, which will ensure that fail over happens from the
    // interest list end point in case Live ServerMonitor is not working
    client1.invoke(new CacheSerializableRunnable("Ensure that the failover from ILEP occurs") {

        public void run2() throws CacheException {
            Region r = cache.getRegion("/" + REGION_NAME);
            String poolName = r.getAttributes().getPoolName();
            assertNotNull(poolName);
            final PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
            assertNotNull(pool);
            pool.acquireConnection();
            try {
                // Used in the case where we don't have a LiveServerMonitorThread
                r.put("ping", "pong1");
            } catch (CacheWriterException itsOK) {
            }
            try {
                // Used in the case where we don't have a LiveServerMonitorThread
                r.put("ping", "pong2");
            } catch (CacheWriterException itsOK) {
            }
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    return pool.getConnectedServerCount() != 2;
                }

                public String description() {
                    return null;
                }
            };
            Wait.waitForCriterion(ev, maxWaitTime, 200, true);
        }
    });
    // put on stopped server
    primary.invoke(() -> put());
    client1.invoke(() -> verifyPut());
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CacheWriterException(org.apache.geode.cache.CacheWriterException) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 97 with WaitCriterion

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

the class InterestListEndpointDUnitTest method verifyPut.

public static void verifyPut() {
    try {
        final Region r = cache.getRegion("/" + REGION_NAME);
        assertNotNull(r);
        WaitCriterion ev = new WaitCriterion() {

            public boolean done() {
                Region.Entry e1 = r.getEntry(k1);
                if (e1 == null)
                    return false;
                Region.Entry e2 = r.getEntry(k2);
                if (e2 == null)
                    return false;
                Object v1 = e1.getValue();
                if (!server_k1.equals(v1))
                    return false;
                Object v2 = e2.getValue();
                if (!client_k2.equals(v2))
                    return false;
                // our state is ready for the assertions
                return true;
            }

            public String description() {
                Region.Entry e1 = r.getEntry(k1);
                if (e1 == null)
                    return "Entry for " + k1 + " is null";
                Region.Entry e2 = r.getEntry(k2);
                if (e2 == null)
                    return "Entry for " + k2 + " is null";
                Object v1 = e1.getValue();
                if (!server_k1.equals(v1)) {
                    return "v1 supposed to be " + server_k1 + " but is " + v1;
                }
                Object v2 = e2.getValue();
                if (!client_k2.equals(v2)) {
                    return "v2 supposed to be " + client_k2 + " but is " + v2;
                }
                return "Test missed a success";
            }
        };
        Wait.waitForCriterion(ev, 20 * 1000, 200, true);
        // yes update
        assertEquals(server_k1, r.getEntry(k1).getValue());
        // no update
        assertEquals(client_k2, r.getEntry(k2).getValue());
    } catch (Exception ex) {
        throw new RuntimeException("failed while region.verifyPut()", ex);
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Region(org.apache.geode.cache.Region) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 98 with WaitCriterion

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

the class InterestListFailoverDUnitTest method _validateEntries.

public static void _validateEntries(final String v) {
    try {
        final Region r = CacheServerTestUtil.getCache().getRegion("/" + REGION_NAME);
        final String key1 = "key-1";
        assertNotNull(r);
        // Verify that 'key-1' was updated
        // assertIndexDetailsEquals("vm2-key-1", r.getEntry("key-1").getValue());
        WaitCriterion wc = new WaitCriterion() {

            String excuse;

            public boolean done() {
                Object val = r.get(key1);
                if (val == null) {
                    return false;
                }
                if (!val.equals("vm2-key-1" + v)) {
                    return false;
                }
                return true;
            }

            public String description() {
                return excuse;
            }
        };
        Wait.waitForCriterion(wc, 40 * 1000, 1000, true);
        // Verify that 'key-6' was not invalidated
        assertEquals("key-6", r.getEntry("key-6").getValue());
    } catch (Exception ex) {
        Assert.fail("failed while r.put()", ex);
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Region(org.apache.geode.cache.Region)

Example 99 with WaitCriterion

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

the class InterestListDUnitTest method validateEntriesK1andK2.

private static void validateEntriesK1andK2(final String vm) {
    WaitCriterion ev = new WaitCriterion() {

        @Override
        public boolean done() {
            try {
                Region r = cache.getRegion(Region.SEPARATOR + REGION_NAME);
                assertNotNull(r);
                if (vm.equals("vm1")) {
                    // Verify that 'key-1' was updated, but 'key-2' was not and contains the
                    // original value
                    assertEquals("vm2-key-1", r.getEntry(key1).getValue());
                    assertEquals("vm1-key-2", r.getEntry(key2).getValue());
                } else {
                    // Verify that 'key-2' was updated, but 'key-1' was not and contains the
                    // original value
                    assertEquals(key1_originalValue, r.getEntry(key1).getValue());
                    assertEquals("vm1-key-2", r.getEntry(key2).getValue());
                }
                return true;
            } catch (AssertionError ex) {
                return false;
            }
        }

        @Override
        public String description() {
            return "waiting for client to apply events from server";
        }
    };
    Wait.waitForCriterion(ev, 5 * 10 * 1000, 200, true);
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Region(org.apache.geode.cache.Region)

Example 100 with WaitCriterion

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

the class InterestRegrListenerDUnitTest method testDurableClientExit_ServerExpressedInterest_NonDurableInterest.

@Test
public void testDurableClientExit_ServerExpressedInterest_NonDurableInterest() throws Exception {
    final Host host = Host.getHost(0);
    final VM serverVM = host.getVM(0);
    final VM clientVM_1 = host.getVM(1);
    final VM clientVM_2 = host.getVM(2);
    final VM clientVM_3 = host.getVM(3);
    serverVM.invoke(() -> InterestRegrListenerDUnitTest.setUpServerVMTask());
    serverVM.invoke(() -> InterestRegrListenerDUnitTest.createServerTask());
    Object[] array = (Object[]) serverVM.invoke(() -> InterestRegrListenerDUnitTest.getCacheServerEndPointTask());
    String hostName = (String) array[0];
    int port = (Integer) array[1];
    Object[] params = new Object[4];
    params[0] = hostName;
    params[1] = port;
    params[2] = true;
    params[3] = "VM_1";
    LogWriterUtils.getLogWriter().info("Starting client1 with server endpoint <" + hostName + ">:" + port);
    clientVM_1.invoke(InterestRegrListenerDUnitTest.class, "setUpClientVMTask", params);
    params[3] = "VM_2";
    LogWriterUtils.getLogWriter().info("Starting client2 with server endpoint <" + hostName + ">:" + port);
    clientVM_2.invoke(InterestRegrListenerDUnitTest.class, "setUpClientVMTask", params);
    params[3] = "VM_3";
    LogWriterUtils.getLogWriter().info("Starting client2 with server endpoint <" + hostName + ">:" + port);
    clientVM_3.invoke(InterestRegrListenerDUnitTest.class, "setUpClientVMTask", params);
    params = new Object[1];
    // non-durable interest
    params[0] = false;
    serverVM.invoke(() -> InterestRegrListenerDUnitTest.doRegisterListenerTask());
    serverVM.invoke(InterestRegrListenerDUnitTest.class, "doExpressInterestOnServerTask", params);
    clientVM_1.invoke(() -> InterestRegrListenerDUnitTest.doClientRegionPutTask());
    clientVM_2.invoke(() -> InterestRegrListenerDUnitTest.doClientRegionPutTask());
    clientVM_3.invoke(() -> InterestRegrListenerDUnitTest.doClientRegionPutTask());
    serverVM.invoke(() -> InterestRegrListenerDUnitTest.doServerRegionPutTask());
    clientVM_1.invoke(() -> InterestRegrListenerDUnitTest.closeClientCacheTask(false));
    clientVM_2.invoke(() -> InterestRegrListenerDUnitTest.closeClientCacheTask(false));
    clientVM_3.invoke(() -> InterestRegrListenerDUnitTest.closeClientCacheTask(false));
    Thread.sleep(2);
    WaitCriterion wc = new WaitCriterion() {

        int registerCount = 0;

        int unregisterCount = 0;

        @Override
        public boolean done() {
            Map<String, Integer> listnerMap = (Map<String, Integer>) serverVM.invoke(() -> InterestRegrListenerDUnitTest.getListenerMapTask());
            LogWriterUtils.getLogWriter().info("Listener Map " + listnerMap);
            registerCount = getMapValueForKey(listnerMap, REGISTER_INTEREST);
            unregisterCount = getMapValueForKey(listnerMap, UNREGISTER_INTEREST);
            if (registerCount == 3 && unregisterCount == 3) {
                return true;
            }
            LogWriterUtils.getLogWriter().info("Waiting for counts to each reach 3.  Current registerCount=" + registerCount + "; unregisterCount=" + unregisterCount);
            return false;
        }

        @Override
        public String description() {
            return "Waiting for counts to each reach 3.  Current registerCount=" + registerCount + "; unregisterCount=" + unregisterCount;
        }
    };
    Wait.waitForCriterion(wc, 20000, 500, true);
    LogWriterUtils.getLogWriter().info("Sleeping till durable client queue are expired and unregister event is called on to listener");
    Thread.sleep((DURABLE_CLIENT_TIMEOUT_TEST + 5) * 1000);
    serverVM.invoke(() -> InterestRegrListenerDUnitTest.closeCacheTask());
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) HashMap(java.util.HashMap) Map(java.util.Map) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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