Search in sources :

Example 91 with SerializableRunnable

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

the class MemberFunctionExecutionDUnitTest method testOnMembersWithoutCache.

@Test
public void testOnMembersWithoutCache() throws Exception {
    DistributedMember member1Id = (DistributedMember) member1.invoke(new SerializableCallable() {

        @Override
        public Object call() {
            disconnectFromDS();
            return getSystem().getDistributedMember();
        }
    });
    member2.invoke(new SerializableRunnable() {

        @Override
        public void run() {
            getSystem();
            ResultCollector<?, ?> rc = FunctionService.onMember(member1Id).execute(new FunctionAdapter() {

                @Override
                public String getId() {
                    return getClass().getName();
                }

                @Override
                public void execute(FunctionContext context) {
                    // This will throw an exception because the cache is not yet created.
                    CacheFactory.getAnyInstance();
                }
            });
            try {
                rc.getResult(30, TimeUnit.SECONDS);
                fail("Should have seen an exception");
            } catch (Exception e) {
                if (!(e.getCause() instanceof FunctionInvocationTargetException)) {
                    Assert.fail("failed", e);
                }
            }
        }
    });
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) InternalDistributedMember(org.apache.geode.distributed.internal.membership.InternalDistributedMember) DistributedMember(org.apache.geode.distributed.DistributedMember) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionAdapter(org.apache.geode.cache.execute.FunctionAdapter) ResultCollector(org.apache.geode.cache.execute.ResultCollector) FunctionContext(org.apache.geode.cache.execute.FunctionContext) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) FunctionException(org.apache.geode.cache.execute.FunctionException) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 92 with SerializableRunnable

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

the class PRClientServerRegionFunctionExecutionDUnitTest method testClientWithoutPool_Bug41832.

@Test
public void testClientWithoutPool_Bug41832() {
    createScenarioWith2Regions();
    Function function = new TestFunction(true, TEST_FUNCTION2);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    toRegister = new Boolean(true);
    SerializableRunnable suspect = new SerializableRunnable() {

        public void run() {
            cache.getLogger().info("<ExpectedException action=add>" + "No target node found for KEY = " + "|Server could not send the reply" + "|Unexpected exception during" + "</ExpectedException>");
        }
    };
    runOnAllServers(suspect);
    client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.serverSingleKeyExecutionWith2Regions(isByName, toRegister));
    SerializableRunnable endSuspect = new SerializableRunnable() {

        public void run() {
            cache.getLogger().info("<ExpectedException action=remove>" + "No target node found for KEY = " + "|Server could not send the reply" + "|Unexpected exception during" + "</ExpectedException>");
        }
    };
    runOnAllServers(endSuspect);
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 93 with SerializableRunnable

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

the class MultiRegionFunctionExecutionDUnitTest method postTearDownCacheTestCase.

@Override
public final void postTearDownCacheTestCase() throws Exception {
    cache = null;
    Invoke.invokeInEveryVM(new SerializableRunnable() {

        public void run() {
            cache = null;
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable)

Example 94 with SerializableRunnable

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

the class PRClientServerRegionFunctionExecutionDUnitTest method testServerSingleKeyExecution_byName_WithoutRegister.

@Test
public void testServerSingleKeyExecution_byName_WithoutRegister() {
    createScenario();
    Function function = new TestFunction(true, TEST_FUNCTION2);
    registerFunctionAtServer(function);
    isByName = new Boolean(true);
    toRegister = new Boolean(false);
    SerializableRunnable suspect = new SerializableRunnable() {

        public void run() {
            cache.getLogger().info("<ExpectedException action=add>" + "No target node found for KEY = " + "|Server could not send the reply" + "|Unexpected exception during" + "</ExpectedException>");
        }
    };
    runOnAllServers(suspect);
    client.invoke(() -> PRClientServerRegionFunctionExecutionDUnitTest.serverSingleKeyExecution(isByName, toRegister));
    SerializableRunnable endSuspect = new SerializableRunnable() {

        public void run() {
            cache.getLogger().info("<ExpectedException action=remove>" + "No target node found for KEY = " + "|Server could not send the reply" + "|Unexpected exception during" + "</ExpectedException>");
        }
    };
    runOnAllServers(endSuspect);
}
Also used : Function(org.apache.geode.cache.execute.Function) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) TestFunction(org.apache.geode.internal.cache.functions.TestFunction) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 95 with SerializableRunnable

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

the class PRTransactionDUnitTest method resumeTx.

@SuppressWarnings("serial")
private SerializableRunnable resumeTx(Op op, TransactionId txId, DistributedMember dm1, DistributedMember dm2) {
    return new SerializableRunnable("resume tx") {

        @Override
        public void run() {
            PartitionedRegion pr = (PartitionedRegion) basicGetCache().getRegion(Region.SEPARATOR + OrderPartitionedRegionName);
            CacheTransactionManager mgr = basicGetCache().getCacheTransactionManager();
            moveBucket(op, dm1, dm2);
            Assertions.assertThatThrownBy(() -> _resumeTx(op, txId, pr, mgr)).isInstanceOf(TransactionDataRebalancedException.class);
        }
    };
}
Also used : PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheTransactionManager(org.apache.geode.cache.CacheTransactionManager)

Aggregations

SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)741 VM (org.apache.geode.test.dunit.VM)405 Test (org.junit.Test)403 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)353 Region (org.apache.geode.cache.Region)347 Host (org.apache.geode.test.dunit.Host)344 Cache (org.apache.geode.cache.Cache)274 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)259 CacheException (org.apache.geode.cache.CacheException)207 AttributesFactory (org.apache.geode.cache.AttributesFactory)204 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)198 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)166 LocalRegion (org.apache.geode.internal.cache.LocalRegion)160 IOException (java.io.IOException)145 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)120 Properties (java.util.Properties)66 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)66 AsyncInvocation (org.apache.geode.test.dunit.AsyncInvocation)65 IgnoredException (org.apache.geode.test.dunit.IgnoredException)61 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)53