Search in sources :

Example 81 with WaitCriterion

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

the class TestCacheCallback method waitForInvocation.

public boolean waitForInvocation(int timeoutMs, long interval) {
    if (!this.invoked) {
        WaitCriterion ev = new WaitCriterion() {

            public boolean done() {
                return invoked;
            }

            public String description() {
                return "listener was never invoked";
            }
        };
        Wait.waitForCriterion(ev, timeoutMs, interval, true);
    }
    return wasInvoked();
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion)

Example 82 with WaitCriterion

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

the class DiskRegionJUnitTest method testEntryUpdateInASynchPersistOnlyForIOExceptionCase.

/**
   * If IOException occurs while updating an entry in an Asynch mode, DiskAccessException should
   * occur & region should be destroyed
   */
@Test
public void testEntryUpdateInASynchPersistOnlyForIOExceptionCase() throws Exception {
    DiskRegionProperties props = new DiskRegionProperties();
    props.setRegionName("IGNORE_EXCEPTION_testEntryUpdateInASynchPersistOnlyForIOExceptionCase");
    props.setOverflow(true);
    props.setRolling(false);
    props.setBytesThreshold(48);
    props.setDiskDirs(dirs);
    props.setPersistBackup(true);
    region = DiskRegionHelperFactory.getAsyncPersistOnlyRegion(cache, props);
    // Get the oplog handle & hence the underlying file & close it
    UninterruptibleFileChannel oplogFileChannel = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
    oplogFileChannel.close();
    region.create("key1", new byte[16]);
    region.create("key2", new byte[16]);
    DiskRegion dr = ((LocalRegion) region).getDiskRegion();
    dr.flushForTesting();
    // Join till the asynch writer terminates
    if (!dr.testWaitForAsyncFlusherThread(2000)) {
        fail("async flusher thread did not terminate");
    }
    Wait.waitForCriterion(new WaitCriterion() {

        @Override
        public boolean done() {
            return cache.isClosed();
        }

        @Override
        public String description() {
            return "Waiting for region IGNORE_EXCEPTION_testEntryUpdateInASynchPersistOnlyForIOExceptionCase to be destroyed.";
        }
    }, 5000, 500, true);
    ((LocalRegion) region).getDiskStore().waitForClose();
    assertTrue(cache.isClosed());
    region = null;
}
Also used : UninterruptibleFileChannel(org.apache.geode.internal.cache.persistence.UninterruptibleFileChannel) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 83 with WaitCriterion

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

the class PartitionedRegionStatsDUnitTest method testDataStoreEntryCount.

/**
   * Test to make sure the datastore entry count is accurate.
   * 
   * @throws InterruptedException
   */
@Test
public void testDataStoreEntryCount() throws InterruptedException {
    // Ok, first problem, GC'd tombstone is counted as an entry
    // To test
    // - modifying a tombstone
    // - modifying and doing tombstone GC?
    final Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm1 = host.getVM(1);
    final VM vm2 = host.getVM(2);
    SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {

        public void run() {
            Cache cache = getCache();
            AttributesFactory attr = new AttributesFactory();
            PartitionAttributesFactory paf = new PartitionAttributesFactory();
            paf.setRedundantCopies(2);
            PartitionAttributes prAttr = paf.create();
            attr.setPartitionAttributes(prAttr);
            cache.createRegion("region1", attr.create());
        }
    };
    vm0.invoke(createPrRegion);
    vm1.invoke(createPrRegion);
    vm0.invoke(new SerializableRunnable("Put some data") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            region.put(Long.valueOf(0), "A");
            region.put(Long.valueOf(1), "A");
            region.put(Long.valueOf(113), "A");
            region.put(Long.valueOf(226), "A");
        }
    });
    validateEntryCount(vm0, 4);
    validateEntryCount(vm1, 4);
    // Do a destroy
    vm0.invoke(new SerializableRunnable("Put some data") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            region.destroy(Long.valueOf(0));
        }
    });
    // We expect the tombstone won't be recorded as part of
    // the entry count
    validateEntryCount(vm0, 3);
    validateEntryCount(vm1, 3);
    // Destroy and modify a tombstone
    vm0.invoke(new SerializableRunnable("Put some data") {

        public void run() {
            Cache cache = getCache();
            Region region = cache.getRegion("region1");
            region.destroy(Long.valueOf(113));
            region.put(Long.valueOf(113), "B");
        }
    });
    validateEntryCount(vm0, 3);
    validateEntryCount(vm1, 3);
    // After GII (which might include the tombstone), a new members
    // should still see only 2 live entries.
    vm2.invoke(createPrRegion);
    // Wait for redundancy to be restored. Once it is the entry count should be
    // 2
    vm2.invoke(new SerializableRunnable("validate stats") {

        public void run() {
            Cache cache = getCache();
            PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
            final PartitionedRegionStats stats = region.getPrStats();
            Wait.waitForCriterion(new WaitCriterion() {

                @Override
                public boolean done() {
                    return stats.getLowRedundancyBucketCount() == 0;
                }

                @Override
                public String description() {
                    return "Redundancy was not satisfied " + stats.getLowRedundancyBucketCount();
                }
            }, 20000, 100, true);
        }
    });
    validateEntryCount(vm2, 3);
    // A tombstone GC shouldn't affect the count.
    vm0.invoke(new SerializableRunnable("Put some data") {

        public void run() {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            TombstoneService tombstoneService = cache.getTombstoneService();
            try {
                tombstoneService.forceBatchExpirationForTests(1);
            } catch (InterruptedException e) {
                Assert.fail("interrupted", e);
            }
        }
    });
    validateEntryCount(vm0, 3);
    validateEntryCount(vm1, 3);
    validateEntryCount(vm2, 3);
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) PartitionAttributes(org.apache.geode.cache.PartitionAttributes) Host(org.apache.geode.test.dunit.Host) 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) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 84 with WaitCriterion

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

the class RemoteTransactionDUnitTest method testTXWithRICommitInDatastore.

@Test
public void testTXWithRICommitInDatastore() throws Exception {
    Host host = Host.getHost(0);
    VM accessor = host.getVM(0);
    VM datastore = host.getVM(1);
    VM client = host.getVM(2);
    initAccessorAndDataStore(accessor, datastore, 0);
    int port = startServer(datastore);
    createClientRegion(client, port, false, true);
    datastore.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
            Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
            Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
            CustId custId = new CustId(1);
            OrderId orderId = new OrderId(1, custId);
            getCache().getCacheTransactionManager().begin();
            custRegion.put(custId, new Customer("foo", "bar"));
            orderRegion.put(orderId, new Order("fooOrder"));
            refRegion.put(custId, new Customer("foo", "bar"));
            getCache().getCacheTransactionManager().commit();
            return null;
        }
    });
    client.invoke(new SerializableCallable() {

        public Object call() throws Exception {
            Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
            Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
            Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
            final ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0];
            WaitCriterion waitForListenerInvocation = new WaitCriterion() {

                public boolean done() {
                    return cl.invoked;
                }

                public String description() {
                    return "listener was never invoked";
                }
            };
            Wait.waitForCriterion(waitForListenerInvocation, 10 * 1000, 10, true);
            return null;
        }
    });
}
Also used : Order(org.apache.geode.internal.cache.execute.data.Order) Customer(org.apache.geode.internal.cache.execute.data.Customer) Host(org.apache.geode.test.dunit.Host) OrderId(org.apache.geode.internal.cache.execute.data.OrderId) NamingException(javax.naming.NamingException) EntryNotFoundException(org.apache.geode.cache.EntryNotFoundException) TransactionWriterException(org.apache.geode.cache.TransactionWriterException) CacheWriterException(org.apache.geode.cache.CacheWriterException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) TransactionDataRebalancedException(org.apache.geode.cache.TransactionDataRebalancedException) TransactionException(org.apache.geode.cache.TransactionException) CacheLoaderException(org.apache.geode.cache.CacheLoaderException) UnsupportedOperationInTransactionException(org.apache.geode.cache.UnsupportedOperationInTransactionException) RollbackException(javax.transaction.RollbackException) TransactionDataNotColocatedException(org.apache.geode.cache.TransactionDataNotColocatedException) CommitConflictException(org.apache.geode.cache.CommitConflictException) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CustId(org.apache.geode.internal.cache.execute.data.CustId) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) TXExpiryJUnitTest(org.apache.geode.TXExpiryJUnitTest) Test(org.junit.Test)

Example 85 with WaitCriterion

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

the class MyFunctionException method startServerHA.

public static void startServerHA() {
    WaitCriterion wc = new WaitCriterion() {

        String excuse;

        public boolean done() {
            return false;
        }

        public String description() {
            return excuse;
        }
    };
    Wait.waitForCriterion(wc, 2000, 500, false);
    Collection bridgeServers = cache.getCacheServers();
    LogWriterUtils.getLogWriter().info("Start Server Bridge Servers list : " + bridgeServers.size());
    Iterator bridgeIterator = bridgeServers.iterator();
    CacheServer bridgeServer = (CacheServer) bridgeIterator.next();
    LogWriterUtils.getLogWriter().info("start Server Bridge Server" + bridgeServer);
    try {
        bridgeServer.start();
    } catch (IOException e) {
        fail("not able to start the server");
    }
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Iterator(java.util.Iterator) Collection(java.util.Collection) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException)

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