Search in sources :

Example 1 with CacheObserverAdapter

use of org.apache.geode.internal.cache.CacheObserverAdapter in project geode by apache.

the class HAClearDUnitTest method postSetUp.

@Override
public final void postSetUp() throws Exception {
    final Host host = Host.getHost(0);
    server1 = host.getVM(0);
    server1.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
    server2 = host.getVM(1);
    server2.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
    client1 = host.getVM(2);
    client2 = host.getVM(3);
    CacheObserverHolder.setInstance(new CacheObserverAdapter());
}
Also used : CacheObserverAdapter(org.apache.geode.internal.cache.CacheObserverAdapter) Host(org.apache.geode.test.dunit.Host)

Example 2 with CacheObserverAdapter

use of org.apache.geode.internal.cache.CacheObserverAdapter in project geode by apache.

the class RegisterInterestBeforeRegionCreationDUnitTest method postSetUp.

@Override
public final void postSetUp() throws Exception {
    final Host host = Host.getHost(0);
    server1 = host.getVM(0);
    server2 = host.getVM(1);
    client1 = host.getVM(2);
    client2 = host.getVM(3);
    CacheObserverHolder.setInstance(new CacheObserverAdapter());
}
Also used : CacheObserverAdapter(org.apache.geode.internal.cache.CacheObserverAdapter) Host(org.apache.geode.test.dunit.Host)

Example 3 with CacheObserverAdapter

use of org.apache.geode.internal.cache.CacheObserverAdapter in project geode by apache.

the class ClearPropagationDUnitTest method postSetUp.

@Override
public final void postSetUp() throws Exception {
    disconnectAllFromDS();
    final Host host = Host.getHost(0);
    // Server1 VM
    server1 = host.getVM(0);
    // Server2 VM
    server2 = host.getVM(1);
    // Client 1 VM
    client1 = host.getVM(2);
    // client 2 VM
    client2 = host.getVM(3);
    int PORT1 = ((Integer) server1.invoke(() -> ClearPropagationDUnitTest.createServerCache())).intValue();
    int PORT2 = ((Integer) server2.invoke(() -> ClearPropagationDUnitTest.createServerCache())).intValue();
    client1.invoke(() -> ClearPropagationDUnitTest.createClientCache(NetworkUtils.getServerHostName(server1.getHost()), new Integer(PORT1), new Integer(PORT2)));
    client2.invoke(() -> ClearPropagationDUnitTest.createClientCache(NetworkUtils.getServerHostName(server1.getHost()), new Integer(PORT1), new Integer(PORT2)));
    CacheObserverHolder.setInstance(new CacheObserverAdapter());
}
Also used : CacheObserverAdapter(org.apache.geode.internal.cache.CacheObserverAdapter) Host(org.apache.geode.test.dunit.Host)

Example 4 with CacheObserverAdapter

use of org.apache.geode.internal.cache.CacheObserverAdapter in project geode by apache.

the class EventIDVerificationDUnitTest method postSetUp.

@Override
public final void postSetUp() throws Exception {
    final Host host = Host.getHost(0);
    vm0 = host.getVM(0);
    vm1 = host.getVM(1);
    // start servers first
    PORT1 = ((Integer) vm0.invoke(() -> EventIDVerificationDUnitTest.createServerCache())).intValue();
    PORT2 = ((Integer) vm1.invoke(() -> EventIDVerificationDUnitTest.createServerCache())).intValue();
    // vm2.invoke(EventIDVerificationDUnitTest.class, "createClientCache", new
    // Object[] { new Integer(PORT1),new Integer(PORT2)});
    createClientCache(NetworkUtils.getServerHostName(host), new Integer(PORT1), new Integer(PORT2));
    CacheObserverHolder.setInstance(new CacheObserverAdapter());
}
Also used : CacheObserverAdapter(org.apache.geode.internal.cache.CacheObserverAdapter) Host(org.apache.geode.test.dunit.Host)

Example 5 with CacheObserverAdapter

use of org.apache.geode.internal.cache.CacheObserverAdapter in project geode by apache.

the class ShutdownAllPersistentGatewaySenderDUnitTest method testGatewaySender.

@Test
public void testGatewaySender() throws Exception {
    IgnoredException.addIgnoredException("Cache is shutting down");
    Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
    Integer nyPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
    vm2.invoke(() -> WANTestBase.createCache(nyPort));
    vm3.invoke(() -> WANTestBase.createCache(nyPort));
    vm2.invoke(() -> WANTestBase.createReceiver());
    vm2.invoke(() -> WANTestBase.createPersistentPartitionedRegion(getTestMethodName() + "_PR", "ln", 1, 100, isOffHeap()));
    vm3.invoke(() -> WANTestBase.createPersistentPartitionedRegion(getTestMethodName() + "_PR", "ln", 1, 100, isOffHeap()));
    vm4.invoke(() -> WANTestBase.createCache(lnPort));
    vm4.invoke(() -> WANTestBase.createSender("ln", 2, false, 100, 400, false, false, null, true));
    vm4.invoke(() -> WANTestBase.startSender("ln"));
    vm4.invoke(() -> WANTestBase.createPersistentPartitionedRegion(getTestMethodName() + "_PR", "ln", 1, 100, isOffHeap()));
    // set the CacheObserver to block the ShutdownAll
    SerializableRunnable waitAtShutdownAll = new SerializableRunnable() {

        @Override
        public void run() {
            LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true;
            CacheObserverHolder.setInstance(new CacheObserverAdapter() {

                @Override
                public void beforeShutdownAll() {
                    final Region region = cache.getRegion(getTestMethodName() + "_PR");
                    Wait.waitForCriterion(new WaitCriterion() {

                        @Override
                        public boolean done() {
                            return region.size() >= 2;
                        }

                        @Override
                        public String description() {
                            return "Wait for wan to have processed several events";
                        }
                    }, 30000, 100, true);
                }
            });
        }
    };
    vm2.invoke(waitAtShutdownAll);
    vm3.invoke(waitAtShutdownAll);
    AsyncInvocation vm4_future = vm4.invokeAsync(() -> WANTestBase.doPuts(getTestMethodName() + "_PR", NUM_KEYS));
    // ShutdownAll will be suspended at observer, so puts will continue
    AsyncInvocation future = shutDownAllMembers(vm2, 2, MAX_WAIT);
    future.join(MAX_WAIT);
    // now restart vm1 with gatewayHub
    LogWriterUtils.getLogWriter().info("restart in VM2");
    vm2.invoke(() -> WANTestBase.createCache(nyPort));
    vm3.invoke(() -> WANTestBase.createCache(nyPort));
    AsyncInvocation vm3_future = vm3.invokeAsync(() -> WANTestBase.createPersistentPartitionedRegion(getTestMethodName() + "_PR", "ln", 1, 100, isOffHeap()));
    vm2.invoke(() -> WANTestBase.createPersistentPartitionedRegion(getTestMethodName() + "_PR", "ln", 1, 100, isOffHeap()));
    vm3_future.join(MAX_WAIT);
    vm3.invoke(new SerializableRunnable() {

        public void run() {
            final Region region = cache.getRegion(getTestMethodName() + "_PR");
            cache.getLogger().info("vm1's region size before restart gatewayHub is " + region.size());
        }
    });
    vm2.invoke(() -> WANTestBase.createReceiver());
    // wait for vm0 to finish its work
    vm4_future.join(MAX_WAIT);
    vm4.invoke(new SerializableRunnable() {

        public void run() {
            Region region = cache.getRegion(getTestMethodName() + "_PR");
            assertEquals(NUM_KEYS, region.size());
        }
    });
    // verify the other side (vm1)'s entries received from gateway
    vm2.invoke(new SerializableRunnable() {

        public void run() {
            final Region region = cache.getRegion(getTestMethodName() + "_PR");
            cache.getLogger().info("vm1's region size after restart gatewayHub is " + region.size());
            Wait.waitForCriterion(new WaitCriterion() {

                public boolean done() {
                    Object lastValue = region.get(NUM_KEYS - 1);
                    if (lastValue != null && lastValue.equals(NUM_KEYS - 1)) {
                        region.getCache().getLogger().info("Last key has arrived, its value is " + lastValue + ", end of wait.");
                        return true;
                    } else
                        return (region.size() == NUM_KEYS);
                }

                public String description() {
                    return "Waiting for destination region to reach size: " + NUM_KEYS + ", current is " + region.size();
                }
            }, MAX_WAIT, 100, true);
            assertEquals(NUM_KEYS, region.size());
        }
    });
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheObserverAdapter(org.apache.geode.internal.cache.CacheObserverAdapter) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

CacheObserverAdapter (org.apache.geode.internal.cache.CacheObserverAdapter)7 Host (org.apache.geode.test.dunit.Host)5 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)3 LocalRegion (org.apache.geode.internal.cache.LocalRegion)2 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)2 Test (org.junit.Test)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 DiskAccessException (org.apache.geode.cache.DiskAccessException)1 Region (org.apache.geode.cache.Region)1 NonTXEntry (org.apache.geode.internal.cache.LocalRegion.NonTXEntry)1 VersionTag (org.apache.geode.internal.cache.versions.VersionTag)1 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)1 IgnoredException (org.apache.geode.test.dunit.IgnoredException)1 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)1 VM (org.apache.geode.test.dunit.VM)1