Search in sources :

Example 26 with AsyncInvocation

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

the class SerialWANPropagationDUnitTest method testReplicatedSerialPropagationWithRemoteRegionDestroy3.

@Test
public void testReplicatedSerialPropagationWithRemoteRegionDestroy3() throws Exception {
    Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
    Integer nyPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
    // these are part of remote site
    createCacheInVMs(nyPort, vm2, vm3);
    // create one RR (RR_1) on remote site
    vm2.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", null, isOffHeap()));
    vm3.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", null, isOffHeap()));
    // create another RR (RR_2) on remote site
    vm2.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", null, isOffHeap()));
    vm3.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", null, isOffHeap()));
    createReceiverInVMs(vm2, vm3);
    // these are part of local site
    createCacheInVMs(lnPort, vm4, vm5, vm6, vm7);
    // create one RR (RR_1) on local site
    vm4.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
    vm5.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
    vm6.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
    vm7.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
    // create another RR (RR_2) on local site
    vm4.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", "ln", isOffHeap()));
    vm5.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", "ln", isOffHeap()));
    vm6.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", "ln", isOffHeap()));
    vm7.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_2", "ln", isOffHeap()));
    // senders are created on local site
    vm4.invoke(() -> WANTestBase.createSender("ln", 2, false, 100, 200, false, false, null, true));
    vm5.invoke(() -> WANTestBase.createSender("ln", 2, false, 100, 200, false, false, null, true));
    // start the senders on local site
    startSenderInVMs("ln", vm4, vm5);
    IgnoredException.addIgnoredException(BatchException70.class.getName());
    IgnoredException.addIgnoredException(ServerOperationException.class.getName());
    // start puts in RR_1 in another thread
    AsyncInvocation inv1 = vm4.invokeAsync(() -> WANTestBase.doPuts(getTestMethodName() + "_RR_1", 1000));
    // start puts in RR_2 in another thread
    AsyncInvocation inv2 = vm4.invokeAsync(() -> WANTestBase.doPuts(getTestMethodName() + "_RR_2", 1000));
    // destroy RR_2 on remote site in the middle
    vm2.invoke(() -> WANTestBase.destroyRegion(getTestMethodName() + "_RR_2"));
    inv1.join();
    inv2.join();
    vm4.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "_RR_1", 1000));
    // in local site
    try {
        vm2.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "_RR_1", 1000));
    } finally {
        System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "GatewaySender.REMOVE_FROM_QUEUE_ON_EXCEPTION", "False");
        vm4.invoke(new CacheSerializableRunnable("UnSetting system property ") {

            public void run2() throws CacheException {
                System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "GatewaySender.REMOVE_FROM_QUEUE_ON_EXCEPTION", "False");
            }
        });
        vm5.invoke(new CacheSerializableRunnable("UnSetting system property ") {

            public void run2() throws CacheException {
                System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "GatewaySender.REMOVE_FROM_QUEUE_ON_EXCEPTION", "False");
            }
        });
    }
}
Also used : CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) BatchException70(org.apache.geode.internal.cache.wan.BatchException70) CacheException(org.apache.geode.cache.CacheException) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 27 with AsyncInvocation

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

the class SerialWANPropagationDUnitTest method testReplicatedSerialPropagationWithRemoteRegionDestroy.

/**
   * 1 region and sender configured on local site and 1 region and a receiver configured on remote
   * site. Puts to the local region are in progress. Remote region is destroyed in the middle.
   */
@Test
public void testReplicatedSerialPropagationWithRemoteRegionDestroy() throws Exception {
    Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
    Integer nyPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
    // these are part of remote site
    createCacheInVMs(nyPort, vm2, vm3);
    createReceiverInVMs(vm2, vm3);
    // these are part of local site
    createCacheInVMs(lnPort, vm4, vm5, vm6, vm7);
    // senders are created on local site
    vm4.invoke(() -> WANTestBase.createSender("ln", 2, false, 100, 500, false, false, null, true));
    vm5.invoke(() -> WANTestBase.createSender("ln", 2, false, 100, 500, false, false, null, true));
    // create one RR (RR_1) on remote site
    vm2.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", null, isOffHeap()));
    vm3.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", null, isOffHeap()));
    // start the senders on local site
    startSenderInVMs("ln", vm4, vm5);
    // create one RR (RR_1) on local site
    vm4.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
    vm5.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
    vm6.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
    vm7.invoke(() -> WANTestBase.createReplicatedRegion(getTestMethodName() + "_RR_1", "ln", isOffHeap()));
    IgnoredException.addIgnoredException(BatchException70.class.getName());
    IgnoredException.addIgnoredException(ServerOperationException.class.getName());
    // start puts in RR_1 in another thread
    AsyncInvocation inv1 = vm4.invokeAsync(() -> WANTestBase.doPuts(getTestMethodName() + "_RR_1", 1000));
    // destroy RR_1 in remote site
    vm2.invoke(() -> WANTestBase.destroyRegion(getTestMethodName() + "_RR_1"));
    inv1.join();
    // verify that all is well in local site. All the events should be present in local region
    vm4.invoke(() -> WANTestBase.validateRegionSize(getTestMethodName() + "_RR_1", 1000));
    // assuming some events might have been dispatched before the remote region was destroyed,
    // sender's region queue will have events less than 1000 but the queue will not be empty.
    // NOTE: this much verification might be sufficient in DUnit. Hydra will take care of
    // more in depth validations.
    vm4.invoke(() -> WANTestBase.verifyRegionQueueNotEmpty("ln"));
}
Also used : BatchException70(org.apache.geode.internal.cache.wan.BatchException70) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 28 with AsyncInvocation

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

the class ClientRegisterInterestAuthDUnitTest method testRegisterInterest.

@Test
public void testRegisterInterest() throws Exception {
    // client1 connects to server as a user not authorized to do any operations
    AsyncInvocation ai1 = client1.invokeAsync(() -> {
        ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        assertNotAuthorized(() -> region.registerInterest("key3"), "DATA:READ:AuthRegion:key3");
    });
    // client2 connects to user as a user authorized to use AuthRegion region
    AsyncInvocation ai2 = client2.invokeAsync(() -> {
        ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        // DATA:READ:AuthRegion:key3;
        region.registerInterest("key3");
    });
    // client3 connects to user as a user authorized to use key1 in AuthRegion region
    AsyncInvocation ai3 = client3.invokeAsync(() -> {
        ClientCache cache = createClientCache("key1User", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        assertNotAuthorized(() -> region.registerInterest("key2"), "DATA:READ:AuthRegion:key2");
    });
    ai1.await();
    ai2.await();
    ai3.await();
}
Also used : SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 29 with AsyncInvocation

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

the class ClientRegisterInterestAuthDUnitTest method testRegisterInterestList.

@Test
public void testRegisterInterestList() throws Exception {
    List<String> keys = new ArrayList<>();
    keys.add("key1");
    keys.add("key2");
    // client1 connects to server as a user not authorized to do any operations
    AsyncInvocation ai1 = client1.invokeAsync(() -> {
        ClientCache cache = createClientCache("stranger", "1234567", server.getPort());
        Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
        assertNotAuthorized(() -> region.registerInterest(keys), "DATA:READ:AuthRegion");
    });
    // client2 connects to user as a user authorized to use AuthRegion region
    AsyncInvocation ai2 = client2.invokeAsync(() -> {
        ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
        Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
        // DATA:READ:AuthRegion;
        region.registerInterest(keys);
    });
    // client3 connects to user as a user authorized to use key1 in AuthRegion region
    AsyncInvocation ai3 = client3.invokeAsync(() -> {
        ClientCache cache = createClientCache("key1User", "1234567", server.getPort());
        Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
        assertNotAuthorized(() -> region.registerInterest(keys), "DATA:READ:AuthRegion");
    });
    ai1.await();
    ai2.await();
    ai3.await();
}
Also used : ArrayList(java.util.ArrayList) SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 30 with AsyncInvocation

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

the class ClientUnregisterInterestAuthDUnitTest method testUnregisterInterest.

@Test
public void testUnregisterInterest() throws Exception {
    // client2 connects to user as a user authorized to use AuthRegion region
    AsyncInvocation ai1 = client2.invokeAsync(() -> {
        ClientCache cache = createClientCache("authRegionUser", "1234567", server.getPort());
        Region region = createProxyRegion(cache, REGION_NAME);
        region.registerInterest("key3");
        // DATA:READ:AuthRegion:key3;
        region.unregisterInterest("key3");
    });
    ai1.await();
}
Also used : SecurityTestUtil.createProxyRegion(org.apache.geode.security.SecurityTestUtil.createProxyRegion) Region(org.apache.geode.cache.Region) ClientCache(org.apache.geode.cache.client.ClientCache) SecurityTestUtil.createClientCache(org.apache.geode.security.SecurityTestUtil.createClientCache) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Aggregations

AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)314 Test (org.junit.Test)280 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)275 VM (org.apache.geode.test.dunit.VM)186 Host (org.apache.geode.test.dunit.Host)175 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)139 Region (org.apache.geode.cache.Region)87 CacheException (org.apache.geode.cache.CacheException)65 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)65 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)61 Cache (org.apache.geode.cache.Cache)44 AttributesFactory (org.apache.geode.cache.AttributesFactory)41 IgnoredException (org.apache.geode.test.dunit.IgnoredException)35 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)28 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)26 LocalRegion (org.apache.geode.internal.cache.LocalRegion)26 IOException (java.io.IOException)25 ArrayList (java.util.ArrayList)25 Ignore (org.junit.Ignore)25 Category (org.junit.experimental.categories.Category)25