Search in sources :

Example 91 with WaitCriterion

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

the class PersistentColocatedPartitionedRegionDUnitTest method testCrashDuringRedundancySatisfaction.

/**
   * Test what happens when we crash in the middle of satisfying redundancy for a colocated bucket.
   * 
   * @throws Throwable
   */
// This test method is disabled because it is failing
// periodically and causing cruise control failures
// See bug #46748
@Test
public void testCrashDuringRedundancySatisfaction() throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    SerializableRunnable createPRs = new SerializableRunnable("region1") {

        public void run() {
            Cache cache = getCache();
            DiskStore ds = cache.findDiskStore("disk");
            if (ds == null) {
                ds = cache.createDiskStoreFactory().setDiskDirs(getDiskDirs()).create("disk");
            }
            AttributesFactory af = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(1);
            // Workaround for 44414 - disable recovery delay so we shutdown
            // vm1 at a predictable point.
            paf.setRecoveryDelay(-1);
            paf.setStartupRecoveryDelay(-1);
            af.setPartitionAttributes(paf.create());
            af.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
            af.setDiskStoreName("disk");
            cache.createRegion(PR_REGION_NAME, af.create());
            paf.setColocatedWith(PR_REGION_NAME);
            af.setPartitionAttributes(paf.create());
            cache.createRegion("region2", af.create());
        }
    };
    // Create the PR on vm0
    vm0.invoke(createPRs);
    // Create some buckets.
    createData(vm0, 0, NUM_BUCKETS, "a");
    createData(vm0, 0, NUM_BUCKETS, "a", "region2");
    vm1.invoke(createPRs);
    // We shouldn't have created any buckets in vm1 yet.
    assertEquals(Collections.emptySet(), getBucketList(vm1));
    // Add an observer that will disconnect before allowing the peer to
    // GII a colocated bucket. This should leave the peer with only the parent
    // bucket
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            DistributionMessageObserver.setInstance(new DistributionMessageObserver() {

                @Override
                public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
                    if (message instanceof RequestImageMessage) {
                        if (((RequestImageMessage) message).regionPath.contains("region2")) {
                            DistributionMessageObserver.setInstance(null);
                            disconnectFromDS();
                        }
                    }
                }
            });
        }
    });
    IgnoredException ex = IgnoredException.addIgnoredException("PartitionOfflineException", vm1);
    try {
        // as we satisfy redundancy with vm1.
        try {
            RebalanceResults rr = rebalance(vm1);
        } catch (Exception expected) {
            // disconnect
            if (!(expected.getCause() instanceof PartitionOfflineException)) {
                throw expected;
            }
        }
        // Wait for vm0 to be closed by the callback
        vm0.invoke(new SerializableCallable() {

            public Object call() throws Exception {
                Wait.waitForCriterion(new WaitCriterion() {

                    public boolean done() {
                        InternalDistributedSystem ds = basicGetSystem();
                        return ds == null || !ds.isConnected();
                    }

                    public String description() {
                        return "DS did not disconnect";
                    }
                }, MAX_WAIT, 100, true);
                return null;
            }
        });
        // close the cache in vm1
        SerializableCallable disconnectFromDS = new SerializableCallable() {

            public Object call() throws Exception {
                disconnectFromDS();
                return null;
            }
        };
        vm1.invoke(disconnectFromDS);
        // Make sure vm0 is disconnected. This avoids a race where we
        // may still in the process of disconnecting even though the our async listener
        // found the system was disconnected
        vm0.invoke(disconnectFromDS);
    } finally {
        ex.remove();
    }
    // Create the cache and PRs on both members
    AsyncInvocation async0 = vm0.invokeAsync(createPRs);
    AsyncInvocation async1 = vm1.invokeAsync(createPRs);
    async0.getResult(MAX_WAIT);
    async1.getResult(MAX_WAIT);
    // Make sure the data was recovered correctly
    checkData(vm0, 0, NUM_BUCKETS, "a");
    // Workaround for bug 46748.
    checkData(vm0, 0, NUM_BUCKETS, "a", "region2");
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) RequestImageMessage(org.apache.geode.internal.cache.InitialImageOperation.RequestImageMessage) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) IgnoredException(org.apache.geode.test.dunit.IgnoredException) PartitionedRegionStorageException(org.apache.geode.cache.PartitionedRegionStorageException) RMIException(org.apache.geode.test.dunit.RMIException) CacheClosedException(org.apache.geode.cache.CacheClosedException) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) IOException(java.io.IOException) DiskStore(org.apache.geode.cache.DiskStore) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) PartitionOfflineException(org.apache.geode.cache.persistence.PartitionOfflineException) DistributionMessage(org.apache.geode.distributed.internal.DistributionMessage) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) IgnoredException(org.apache.geode.test.dunit.IgnoredException) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributionMessageObserver(org.apache.geode.distributed.internal.DistributionMessageObserver) DistributionManager(org.apache.geode.distributed.internal.DistributionManager) RebalanceResults(org.apache.geode.cache.control.RebalanceResults) Cache(org.apache.geode.cache.Cache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 92 with WaitCriterion

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

the class PersistentPartitionedRegionDUnitTest method testRevokedMemberRedundancy1ImmediateRecovery.

/**
   * Test to make sure that we recreate a bucket if a member is revoked, and that we do it
   * immediately if recovery delay is set to 0.
   * 
   * @throws Throwable
   */
@Test
public void testRevokedMemberRedundancy1ImmediateRecovery() throws Throwable {
    // I see this test failing because it finds the ds disconnected. Trying
    disconnectAllFromDS();
    // this as a fix.
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    createPR(vm0, 1, 0);
    createPR(vm1, 1, 0);
    createData(vm0, 0, NUM_BUCKETS, "a");
    // This should do nothing because we have satisfied redundancy.
    createPR(vm2, 1, 0);
    assertEquals(Collections.emptySet(), getBucketList(vm2));
    Set<Integer> vm0Buckets = getBucketList(vm0);
    final Set<Integer> lostBuckets = getBucketList(vm1);
    closeCache(vm1);
    // VM2 should pick up the slack
    Wait.waitForCriterion(new WaitCriterion() {

        public boolean done() {
            Set<Integer> vm2Buckets = getBucketList(vm2);
            return lostBuckets.equals(vm2Buckets);
        }

        public String description() {
            return "expected to recover " + lostBuckets + " buckets, now have " + getBucketList(vm2);
        }
    }, 30000, 500, true);
    createData(vm0, 0, NUM_BUCKETS, "b");
    // VM1 should recover, but it shouldn't host the bucket anymore
    createPR(vm1, 1, 0);
    // The data shouldn't be affected.
    checkData(vm1, 0, NUM_BUCKETS, "b");
    // restart everything, and make sure it comes back correctly.
    closeCache(vm1);
    closeCache(vm0);
    closeCache(vm2);
    AsyncInvocation async1 = createPRAsync(vm1, 1);
    AsyncInvocation async0 = createPRAsync(vm0, 1);
    // Make sure we wait for vm2, because it's got the latest copy of the bucket
    async1.join(50);
    // FAILED On this line
    assertTrue(async1.isAlive());
    AsyncInvocation async2 = createPRAsync(vm2, 1);
    async2.getResult(MAX_WAIT);
    async0.getResult(MAX_WAIT);
    async1.getResult(MAX_WAIT);
    // The data shouldn't be affected.
    checkData(vm1, 0, NUM_BUCKETS, "b");
    assertEquals(Collections.emptySet(), getBucketList(vm1));
    assertEquals(vm0Buckets, getBucketList(vm0));
    assertEquals(vm0Buckets, getBucketList(vm2));
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Set(java.util.Set) HashSet(java.util.HashSet) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test)

Example 93 with WaitCriterion

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

the class DestroyEntryPropagationDUnitTest method testVerifyDestroyNotReceivedBySender.

/**
   * This tests whether the destroy are received by the sender or not if there are situation of
   * Interest List fail over
   */
// GEODE-897: random port, time sensitive, waitForCriterion, 2 minute
@Category(FlakyTest.class)
// timeouts, eats exception (1 fixed)
@Test
public void testVerifyDestroyNotReceivedBySender() {
    final int maxWaitTime = Integer.getInteger(WAIT_PROPERTY, WAIT_DEFAULT).intValue();
    // First create entries on both servers via the two client
    vm2.invoke(() -> DestroyEntryPropagationDUnitTest.createEntriesK1andK2());
    vm3.invoke(() -> DestroyEntryPropagationDUnitTest.createEntriesK1andK2());
    vm2.invoke(() -> DestroyEntryPropagationDUnitTest.registerKey1());
    vm3.invoke(() -> DestroyEntryPropagationDUnitTest.registerKey1());
    // Induce fail over of InterestList Endpoint to Server 2 by killing server1
    vm0.invoke(() -> DestroyEntryPropagationDUnitTest.killServer(new Integer(PORT1)));
    // Wait for 10 seconds to allow fail over. This would mean that Interest
    // has failed over to Server2.
    vm2.invoke(new CacheSerializableRunnable("Wait for server on port1 to be dead") {

        public void run2() throws CacheException {
            Region r = cache.getRegion(REGION_NAME);
            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", "pong1");
            } catch (CacheWriterException itsOK) {
            }
            String poolName = r.getAttributes().getPoolName();
            assertNotNull(poolName);
            final PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
            assertNotNull(pool);
            WaitCriterion ev = new WaitCriterion() {

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

                public String description() {
                    return null;
                }
            };
            Wait.waitForCriterion(ev, maxWaitTime, 200, true);
        }
    });
    // Start Server1 again so that both clients1 & Client 2 will establish
    // connection to server1 too.
    vm0.invoke(() -> DestroyEntryPropagationDUnitTest.startServer(new Integer(PORT1)));
    vm2.invoke(new CacheSerializableRunnable("Wait for server on port1 to spring to life") {

        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);
            WaitCriterion ev = new WaitCriterion() {

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

                public String description() {
                    return null;
                }
            };
            Wait.waitForCriterion(ev, maxWaitTime, 200, true);
        }
    });
    // Do a destroy on Server1 via Connection object from client1.
    // Client1 should not receive updated value while client2 should receive
    vm2.invoke(() -> acquireConnectionsAndDestroyEntriesK1andK2());
    // pause(10000);
    // Check if both the puts ( on key1 & key2 ) have reached the servers
    vm0.invoke(() -> DestroyEntryPropagationDUnitTest.verifyEntriesAreDestroyed());
    vm1.invoke(() -> DestroyEntryPropagationDUnitTest.verifyEntriesAreDestroyed());
    vm2.invoke(() -> DestroyEntryPropagationDUnitTest.verifyNoDestroyEntryInSender());
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) Region(org.apache.geode.cache.Region) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CacheWriterException(org.apache.geode.cache.CacheWriterException) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 94 with WaitCriterion

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

the class DurableClientBug39997DUnitTest method testNoServerAvailableOnStartup.

@Test
public void testNoServerAvailableOnStartup() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final String hostName = NetworkUtils.getServerHostName(host);
    final int port = AvailablePortHelper.getRandomAvailableTCPPort();
    vm0.invoke(new SerializableRunnable("create cache") {

        public void run() {
            getSystem(getClientProperties());
            PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(hostName, port).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).create("DurableClientReconnectDUnitTestPool");
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            factory.setPoolName(p.getName());
            Cache cache = getCache();
            Region region1 = cache.createRegion("region", factory.create());
            cache.readyForEvents();
            try {
                region1.registerInterest("ALL_KEYS");
                fail("Should have received an exception trying to register interest");
            } catch (NoSubscriptionServersAvailableException expected) {
            // this is expected
            }
        }
    });
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            cache.createRegion("region", factory.create());
            CacheServer server = cache.addCacheServer();
            server.setPort(port);
            try {
                server.start();
            } catch (IOException e) {
                Assert.fail("couldn't start server", e);
            }
        }
    });
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            final Region region = cache.getRegion("region");
            Wait.waitForCriterion(new WaitCriterion() {

                public String description() {
                    return "Wait for register interest to succeed";
                }

                public boolean done() {
                    try {
                        region.registerInterest("ALL_KEYS");
                    } catch (NoSubscriptionServersAvailableException e) {
                        return false;
                    }
                    return true;
                }
            }, 30000, 1000, true);
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) AttributesFactory(org.apache.geode.cache.AttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) Cache(org.apache.geode.cache.Cache) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 95 with WaitCriterion

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

the class ConnectionProxyJUnitTest method testThreadIdToSequenceIdMapExpiryNegative.

@Test
public void testThreadIdToSequenceIdMapExpiryNegative() {
    int port3 = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server = null;
    try {
        try {
            server = this.cache.addCacheServer();
            server.setMaximumTimeBetweenPings(10000);
            server.setPort(port3);
            server.start();
        } catch (Exception e) {
            e.printStackTrace();
            fail("Failed to create server");
        }
        try {
            PoolFactory pf = PoolManager.createFactory();
            pf.addServer("localhost", port3);
            pf.setSubscriptionEnabled(true);
            pf.setSubscriptionRedundancy(-1);
            pf.setSubscriptionMessageTrackingTimeout(10000);
            proxy = (PoolImpl) pf.create("clientPool");
            final EventID eid = new EventID(new byte[0], 1, 1);
            if (proxy.verifyIfDuplicate(eid)) {
                fail(" eid should not be duplicate as it is a new entry");
            }
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    return proxy.verifyIfDuplicate(eid);
                }

                public String description() {
                    return null;
                }
            };
            Wait.waitForCriterion(ev, 20 * 1000, 200, true);
        } catch (Exception ex) {
            ex.printStackTrace();
            fail("Failed to initialize client");
        }
    } finally {
        if (server != null) {
            server.stop();
        }
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheServer(org.apache.geode.cache.server.CacheServer) EventID(org.apache.geode.internal.cache.EventID) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

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