Search in sources :

Example 56 with AsyncInvocation

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

the class ShowMissingDiskStoresDUnitTest method restartServerAsync.

private AsyncInvocation restartServerAsync(MemberVM member) throws Exception {
    String memberWorkingDir = member.getWorkingDir().getAbsolutePath();
    int locatorPort = locator.getPort();
    AsyncInvocation restart = member.invokeAsync(() -> {
        ServerLauncher serverLauncher = new ServerLauncher.Builder().setWorkingDirectory(memberWorkingDir).setMemberName("server-1").set(LOCATORS, "localhost[" + locatorPort + "]").build();
        serverLauncher.start();
    });
    return restart;
}
Also used : CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) ServerLauncher(org.apache.geode.distributed.ServerLauncher)

Example 57 with AsyncInvocation

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

the class ClearMultiVmDUnitTest method testGiiandClear.

// end of testClearExceptions
@Test
public void testGiiandClear() throws Throwable {
    if (false) {
        getSystem().getLogWriter().severe("testGiiandClear skipped because of bug 34963");
    } else {
        Host host = Host.getHost(0);
        VM vm0 = host.getVM(0);
        VM vm1 = host.getVM(1);
        SerializableRunnable create = new CacheSerializableRunnable("create mirrored region") {

            public void run2() throws CacheException {
                AttributesFactory factory1 = new AttributesFactory();
                factory1.setScope(Scope.DISTRIBUTED_ACK);
                factory1.setDataPolicy(DataPolicy.REPLICATE);
                RegionAttributes attr1 = factory1.create();
                mirroredRegion = cache.createRegion("mirrored", attr1);
                // reset slow
                org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
            }
        };
        vm0.invoke(create);
        vm0.invoke(new CacheSerializableRunnable("put initial data") {

            public void run2() throws CacheException {
                for (int i = 0; i < 1000; i++) {
                    mirroredRegion.put(new Integer(i), (new Integer(i)).toString());
                }
            }
        });
        // slow down image processing to make it more likely to get async updates
        vm1.invoke(new SerializableRunnable("set slow image processing") {

            public void run() {
                // if this is a no_ack test, then we need to slow down more because of the
                // pauses in the nonblocking operations
                int pause = 50;
                org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = pause;
            }
        });
        // now do the get initial image in vm1
        AsyncInvocation async1 = vm1.invokeAsync(create);
        // try to time a distributed clear to happen in the middle of gii
        vm0.invoke(new SerializableRunnable("call clear when gii") {

            public void run() {
                try {
                    Thread.sleep(3 * 1000);
                } catch (InterruptedException ex) {
                    fail("interrupted");
                }
                mirroredRegion.clear();
                assertEquals(0, mirroredRegion.size());
            }
        });
        ThreadUtils.join(async1, 30 * 1000);
        if (async1.exceptionOccurred()) {
            Assert.fail("async1 failed", async1.getException());
        }
        SerializableRunnable validate = new CacheSerializableRunnable("validate for region size") {

            public void run2() throws CacheException {
                assertEquals(0, mirroredRegion.size());
            }
        };
        vm0.invoke(validate);
        vm1.invoke(validate);
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheException(org.apache.geode.cache.CacheException) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 58 with AsyncInvocation

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

the class PartitionedRegionCreationDUnitTest method testConcurrentCreation_2.

/**
   * This test create regions with scope = DISTRIBUTED_NO_ACK and then validating these partition
   * regons. Test specially added for SQL fabric testing since that always creates regions in
   * parallel.
   * 
   * @throws Exception
   */
@Test
public void testConcurrentCreation_2() throws Exception {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    int AsyncInvocationArrSize = 4;
    final String regionNamePrefix = "PARTREG";
    final String replRegion = "TESTREG";
    CacheSerializableRunnable createRepl = new CacheSerializableRunnable("Create Repl") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            AttributesFactory attr = new AttributesFactory();
            attr.setScope(Scope.DISTRIBUTED_ACK);
            attr.setDataPolicy(DataPolicy.REPLICATE);
            cache.createRegion(replRegion, attr.create());
        }
    };
    createRepl.run2();
    vm0.invoke(createRepl);
    vm1.invoke(createRepl);
    vm2.invoke(createRepl);
    vm3.invoke(createRepl);
    AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize];
    CacheSerializableRunnable createPR = new CacheSerializableRunnable("Create PR") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region partitionedregion = null;
            AttributesFactory attr = new AttributesFactory();
            attr.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(2).create());
            // wait for put
            Region reg = cache.getRegion(replRegion);
            Region.Entry regEntry;
            while ((regEntry = reg.getEntry("start")) == null || regEntry.getValue() == null) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            for (int index = 0; index < MAX_REGIONS; ++index) {
                final String regionName = regionNamePrefix + String.valueOf(index);
                partitionedregion = cache.createRegion(regionName, attr.create());
                assertNotNull("Partitioned Region ref null", partitionedregion);
                assertNotNull("Cache does not contain PR " + regionName, cache.getRegion(regionName));
                assertTrue("Partitioned Region ref claims to be destroyed", !partitionedregion.isDestroyed());
            }
        }
    };
    // create accessor on the main thread
    CacheSerializableRunnable createAccessorPR = new CacheSerializableRunnable("Create Accessor PR") {

        @Override
        public void run2() throws CacheException {
            Cache cache = getCache();
            Region partitionedregion = null;
            AttributesFactory attr = new AttributesFactory();
            attr.setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(2).setLocalMaxMemory(0).create());
            // wait for put
            Region reg = cache.getRegion(replRegion);
            Region.Entry regEntry;
            while ((regEntry = reg.getEntry("start")) == null || regEntry.getValue() == null) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            for (int index = 0; index < MAX_REGIONS; ++index) {
                final String regionName = regionNamePrefix + String.valueOf(index);
                partitionedregion = cache.createRegion(regionName, attr.create());
                assertNotNull("Partitioned Region ref null", partitionedregion);
                assertNotNull("Cache does not contain PR " + regionName, cache.getRegion(regionName));
                assertTrue("Partitioned Region ref claims to be destroyed", !partitionedregion.isDestroyed());
            }
        }
    };
    Thread th = new Thread(() -> createAccessorPR.run());
    th.start();
    async[0] = vm0.invokeAsync(createPR);
    async[1] = vm1.invokeAsync(createPR);
    async[2] = vm2.invokeAsync(createPR);
    async[3] = vm3.invokeAsync(createPR);
    // do the put
    Region reg = getCache().getRegion(replRegion);
    reg.put("start", "true");
    /** main thread is waiting for the other threads to complete */
    for (int count = 0; count < AsyncInvocationArrSize; count++) {
        ThreadUtils.join(async[count], 30 * 1000);
    }
    th.join(30 * 1000);
    for (int count = 0; count < AsyncInvocationArrSize; count++) {
        if (async[count].exceptionOccurred()) {
            Assert.fail("exception during " + count, async[count].getException());
        }
    }
    // //validating that regions are successfully created
    vm0.invoke(getCacheSerializableRunnableForPRValidate(regionNamePrefix));
    vm1.invoke(getCacheSerializableRunnableForPRValidate(regionNamePrefix));
    vm2.invoke(getCacheSerializableRunnableForPRValidate(regionNamePrefix));
    vm3.invoke(getCacheSerializableRunnableForPRValidate(regionNamePrefix));
}
Also used : Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 59 with AsyncInvocation

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

the class PartitionedRegionCreationDUnitTest method testPartitionRegionRegistration.

/**
   * This tests registration of partition region is happened in allpartition region
   * 
   * @throws Exception
   */
@Test
public void testPartitionRegionRegistration() throws Throwable {
    final String name = getUniqueName();
    // Cache cache = getCache();
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    LogWriterUtils.getLogWriter().info("*****REGISTRATION TEST STARTED*****");
    int AsyncInvocationArrSize = 8;
    AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize];
    async[0] = vm0.invokeAsync(getCacheSerializableRunnableForPRCreate(name, MAX_REGIONS, 0, "NONE"));
    async[1] = vm1.invokeAsync(getCacheSerializableRunnableForPRCreate(name, MAX_REGIONS, 0, "NONE"));
    async[2] = vm2.invokeAsync(getCacheSerializableRunnableForPRCreate(name, MAX_REGIONS, 0, "NONE"));
    async[3] = vm3.invokeAsync(getCacheSerializableRunnableForPRCreate(name, MAX_REGIONS, 0, "NONE"));
    /** main thread is waiting for the other threads to complete */
    for (int count = 0; count < 4; count++) {
        ThreadUtils.join(async[count], 30 * 1000);
    }
    for (int count = 0; count < 4; count++) {
        if (async[count].exceptionOccurred()) {
            Assert.fail("exception during " + count, async[count].getException());
        }
    }
    async[4] = vm0.invokeAsync(getCacheSerializableRunnableForPRRegistration(name));
    async[5] = vm1.invokeAsync(getCacheSerializableRunnableForPRRegistration(name));
    async[6] = vm2.invokeAsync(getCacheSerializableRunnableForPRRegistration(name));
    async[7] = vm3.invokeAsync(getCacheSerializableRunnableForPRRegistration(name));
    /** main thread is waiting for the other threads to complete */
    for (int count = 4; count < AsyncInvocationArrSize; count++) {
        ThreadUtils.join(async[count], 30 * 1000);
    }
    for (int count = 4; count < AsyncInvocationArrSize; count++) {
        if (async[count].exceptionOccurred()) {
            Assert.fail("exception during " + count, async[count].getException());
        }
    }
    LogWriterUtils.getLogWriter().info("*****REGISTRATION TEST ENDED*****");
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 60 with AsyncInvocation

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

the class PartitionedRegionCreationDUnitTest method testPartitionRegionInitialization.

/**
   * This test creates partition region with scope = DISTRIBUTED_ACK and tests whether all the
   * attributes of partiotion region are properlt initialized
   * 
   * @throws Exception
   */
// GEODE-1104: time sensitive, async actions
@Category(FlakyTest.class)
@Test
public void testPartitionRegionInitialization() throws Throwable {
    final String name = getUniqueName();
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    LogWriterUtils.getLogWriter().info("*****INITIALIZATION TEST STARTED*****");
    int AsyncInvocationArrSize = 8;
    AsyncInvocation[] async = new AsyncInvocation[AsyncInvocationArrSize];
    async[0] = vm0.invokeAsync(getCacheSerializableRunnableForPRCreate(name, MAX_REGIONS, 0, "NONE"));
    async[1] = vm1.invokeAsync(getCacheSerializableRunnableForPRCreate(name, MAX_REGIONS, 0, "NONE"));
    async[2] = vm2.invokeAsync(getCacheSerializableRunnableForPRCreate(name, MAX_REGIONS, 0, "NONE"));
    async[3] = vm3.invokeAsync(getCacheSerializableRunnableForPRCreate(name, MAX_REGIONS, 0, "NONE"));
    /** main thread is waiting for the other threads to complete */
    for (int count = 0; count < 4; count++) {
        ThreadUtils.join(async[count], 30 * 1000);
    }
    for (int count = 0; count < 4; count++) {
        if (async[count].exceptionOccurred()) {
            Assert.fail("exception during " + count, async[count].getException());
        }
    }
    async[4] = vm0.invokeAsync(getCacheSerializableRunnableForPRInitialize());
    async[5] = vm1.invokeAsync(getCacheSerializableRunnableForPRInitialize());
    async[6] = vm2.invokeAsync(getCacheSerializableRunnableForPRInitialize());
    async[7] = vm3.invokeAsync(getCacheSerializableRunnableForPRInitialize());
    /** main thread is waiting for the other threads to complete */
    for (int count = 4; count < AsyncInvocationArrSize; count++) {
        ThreadUtils.join(async[count], 30 * 1000);
    }
    for (int count = 4; count < AsyncInvocationArrSize; count++) {
        if (async[count].exceptionOccurred()) {
            Assert.fail("exception during " + count, async[count].getException());
        }
    }
    LogWriterUtils.getLogWriter().info("*****INITIALIZATION TEST ENDED*****");
}
Also used : VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) 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