Search in sources :

Example 61 with IgnoredException

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

the class CacheXml66DUnitTest method testCreateSameRegionTwice.

/**
   * Tests to make sure that we cannot create the same region multiple times in a {@code cache.xml}
   * file.
   */
@Test
public void testCreateSameRegionTwice() throws Exception {
    CacheCreation cache = new CacheCreation();
    RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
    String name = "root";
    cache.createRegion(name, attrs);
    try {
        cache.createRegion(name, attrs);
        fail("Should have thrown a RegionExistsException");
    } catch (RegionExistsException ex) {
    // pass...
    }
    setXmlFile(findFile("sameRootRegion.xml"));
    IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
    try {
        getCache();
        fail("Should have thrown a CacheXmlException");
    } catch (CacheXmlException ex) {
        Throwable cause = ex.getCause();
        assertTrue(cause instanceof SAXException);
        cause = ((SAXException) cause).getException();
        if (!(cause instanceof RegionExistsException)) {
            Assert.fail("Expected a RegionExistsException, not a " + cause.getClass().getName(), cause);
        }
    } finally {
        expectedException.remove();
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) IgnoredException(org.apache.geode.test.dunit.IgnoredException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Example 62 with IgnoredException

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

the class CacheXml66DUnitTest method testUnknownNamedAttributes.

/**
   * Tests that trying to parse an XML file that declares a region whose attributes refer to an
   * unknown named region attributes throws an {@link IllegalStateException}.
   */
@Test
public void testUnknownNamedAttributes() throws Exception {
    setXmlFile(findFile("unknownNamedAttributes.xml"));
    IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.RegionAttributesCreation_CANNOT_REFERENCE_NONEXISTING_REGION_ATTRIBUTES_NAMED_0.toLocalizedString());
    try {
        getCache();
        fail("Should have thrown an IllegalStateException");
    } catch (IllegalStateException ex) {
    // pass...
    } finally {
        expectedException.remove();
    }
}
Also used : IgnoredException(org.apache.geode.test.dunit.IgnoredException) Test(org.junit.Test)

Example 63 with IgnoredException

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

the class CacheXml66DUnitTest method testNonExistentFile.

/**
   * Tests creating a cache with a non-existent XML file
   */
@Test
public void testNonExistentFile() throws Exception {
    // System.out.println("testNonExistentFile - start: " + System.currentTimeMillis());
    File nonExistent = new File(this.getName() + ".xml");
    nonExistent.delete();
    // System.out.println("testNonExistentFile - deleted: " + System.currentTimeMillis());
    setXmlFile(nonExistent);
    // System.out.println("testNonExistentFile - set: " + System.currentTimeMillis());
    IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.GemFireCache_DECLARATIVE_CACHE_XML_FILERESOURCE_0_DOES_NOT_EXIST.toLocalizedString(nonExistent.getPath()));
    try {
        getCache();
        fail("Should have thrown a CacheXmlException");
    } catch (CacheXmlException ex) {
    // System.out.println("testNonExistentFile - caught: " + System.currentTimeMillis());
    // pass...
    } finally {
        expectedException.remove();
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) File(java.io.File) Test(org.junit.Test)

Example 64 with IgnoredException

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

the class MultiVMRegionTestCase method testNBRegionDestructionDuringGetInitialImage.

@Test
public void testNBRegionDestructionDuringGetInitialImage() throws Exception {
    assumeTrue(supportsReplication());
    final String name = this.getUniqueName();
    final byte[][] values = new byte[NB1_NUM_ENTRIES][];
    for (int i = 0; i < NB1_NUM_ENTRIES; i++) {
        values[i] = new byte[NB1_VALUE_SIZE];
        Arrays.fill(values[i], (byte) 0x42);
    }
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm2 = host.getVM(2);
    vm0.invoke(new CacheSerializableRunnable("Create Nonmirrored Region") {

        @Override
        public void run2() throws CacheException {
            {
                // root region must be DACK because its used to sync up async subregions
                AttributesFactory factory = new AttributesFactory();
                factory.setScope(Scope.DISTRIBUTED_ACK);
                factory.setDataPolicy(DataPolicy.EMPTY);
                createRootRegion(factory.create());
            }
            {
                AttributesFactory factory = new AttributesFactory(getRegionAttributes());
                createRegion(name, factory.create());
            }
            // reset slow
            org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Put initial data") {

        @Override
        public void run2() throws CacheException {
            Region region = getRootRegion().getSubregion(name);
            for (int i = 0; i < NB1_NUM_ENTRIES; i++) {
                region.put(new Integer(i), values[i]);
            }
            assertEquals(NB1_NUM_ENTRIES, region.keySet().size());
        }
    });
    // attachDebugger(vm0, "vm0");
    // attachDebugger(vm2, "vm2");
    // start asynchronous process that does updates to the data
    AsyncInvocation async = vm0.invokeAsync(new CacheSerializableRunnable("Do Nonblocking Operations") {

        @Override
        public void run2() throws CacheException {
            // give the gii guy a chance to start
            Wait.pause(200);
            Region region = getRootRegion().getSubregion(name);
            // wait for profile of getInitialImage cache to show up
            final org.apache.geode.internal.cache.CacheDistributionAdvisor adv = ((org.apache.geode.internal.cache.DistributedRegion) region).getCacheDistributionAdvisor();
            // int numProfiles;
            final int expectedProfiles = 1;
            WaitCriterion ev = new WaitCriterion() {

                @Override
                public boolean done() {
                    return expectedProfiles == adv.adviseReplicates().size();
                }

                @Override
                public String description() {
                    return "profile count never became exactly " + expectedProfiles;
                }
            };
            Wait.waitForCriterion(ev, 60 * 1000, 200, true);
            // before the get initial image is complete.
            for (int i = 1; i < 301; i += 2) {
                // getLogWriter().info("doing nonblocking op #"+i);
                Object key = new Integer(i);
                switch(i % 6) {
                    case // UPDATE
                    1:
                        // use the current timestamp so we know when it happened
                        // we could have used last modification timestamps, but
                        // this works without enabling statistics
                        Object value = new Long(System.currentTimeMillis());
                        region.put(key, value);
                        // }
                        break;
                    case // INVALIDATE
                    3:
                        region.invalidate(key);
                        if (region.getAttributes().getScope().isDistributedAck()) {
                            // do a nonblocking netSearch
                            value = region.get(key);
                            assertNull("Expected null value for key: " + i + " but got " + value, value);
                        }
                        break;
                    case // DESTROY
                    5:
                        region.destroy(key);
                        if (region.getAttributes().getScope().isDistributedAck()) {
                            // do a nonblocking netSearch
                            assertNull(region.get(key));
                        }
                        break;
                    default:
                        fail("unexpected modulus result: " + i);
                        break;
                }
            }
            // at magical number 301, do a region destruction
            // getLogWriter().info("doing destroyRegion");
            region.destroyRegion();
            // getLogWriter().info("finished destroyRegion");
            // now do a put and our DACK root region which will not complete
            // until processed on otherside which means everything done before this
            // point has been processed
            {
                Region rr = getRootRegion();
                if (rr != null) {
                    rr.put("DONE", "FLUSH_OPS");
                }
            }
        }
    });
    IgnoredException ex = IgnoredException.addIgnoredException("RegionDestroyedException");
    try {
        // in the meantime, do the get initial image in vm2
        AsyncInvocation asyncGII = vm2.invokeAsync(new CacheSerializableRunnable("Create Mirrored Region") {

            @Override
            public void run2() throws CacheException {
                if (!getRegionAttributes().getScope().isGlobal()) {
                    int pause = 200;
                    org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = pause;
                }
                beginCacheXml();
                {
                    // root region must be DACK because its used to sync up async subregions
                    AttributesFactory factory = new AttributesFactory();
                    factory.setScope(Scope.DISTRIBUTED_ACK);
                    factory.setDataPolicy(DataPolicy.NORMAL);
                    factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
                    createRootRegion(factory.create());
                }
                {
                    RegionAttributes ra = getRegionAttributes();
                    AttributesFactory factory = new AttributesFactory(ra);
                    if (ra.getDataPolicy().withPersistence()) {
                        factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
                    } else {
                        factory.setDataPolicy(DataPolicy.REPLICATE);
                    }
                    createRegion(name, factory.create());
                }
                finishCacheXml(name);
                // reset slow
                org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
                // if global scope, the region doesn't get destroyed until after region creation
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException ie) {
                    fail("interrupted");
                }
                assertTrue(getRootRegion().getSubregion(name) == null || getRegionAttributes().getScope().isGlobal());
            }
        });
        if (getRegionAttributes().getScope().isGlobal()) {
            // wait for nonblocking operations to complete
            ThreadUtils.join(async, 30 * 1000);
            if (async.exceptionOccurred()) {
                fail("async invocation failed", async.getException());
            }
            vm2.invoke(new SerializableRunnable("Set fast image processing") {

                @Override
                public void run() {
                    org.apache.geode.internal.cache.InitialImageOperation.slowImageProcessing = 0;
                }
            });
            org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("after async nonblocking ops complete");
        }
        // wait for GII to complete
        // getLogWriter().info("starting wait for GetInitialImage Completion");
        ThreadUtils.join(asyncGII, 30 * 1000);
        org.apache.geode.test.dunit.LogWriterUtils.getLogWriter().info("Complete GetInitialImage at: " + System.currentTimeMillis());
        if (getRegionAttributes().getScope().isGlobal()) {
            // wait for nonblocking operations to complete
            ThreadUtils.join(async, 30 * 1000);
        }
        if (async.exceptionOccurred()) {
            fail("async failed", async.getException());
        }
        if (asyncGII.exceptionOccurred()) {
            fail("asyncGII failed", asyncGII.getException());
        }
    } finally {
        ex.remove();
    }
}
Also used : CacheException(org.apache.geode.cache.CacheException) RegionAttributes(org.apache.geode.cache.RegionAttributes) AsyncInvocation(org.apache.geode.test.dunit.AsyncInvocation) AttributesFactory(org.apache.geode.cache.AttributesFactory) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) IgnoredException(org.apache.geode.test.dunit.IgnoredException) StoredObject(org.apache.geode.internal.offheap.StoredObject) Test(org.junit.Test) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 65 with IgnoredException

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

the class GIIFlowControlDUnitTest method doCloseTest.

public void doCloseTest(boolean disconnect) throws Throwable {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    Invoke.invokeInEveryVM(new SerializableRunnable("set chunk size") {

        public void run() {
            InitialImageOperation.CHUNK_SIZE_IN_BYTES = 10;
            InitialImageOperation.CHUNK_PERMITS = 2;
        }
    });
    InitialImageOperation.CHUNK_SIZE_IN_BYTES = 10;
    InitialImageOperation.CHUNK_PERMITS = 2;
    vm1.invoke(new SerializableRunnable("Add flow control observer") {

        public void run() {
            observer = new FlowControlObserver();
            DistributionMessageObserver.setInstance(observer);
            getCache();
            observer.start();
        }
    });
    IgnoredException expectedEx = null;
    try {
        createRegion(vm0);
        createData(vm0, 0, 50, "1234567890");
        createRegionAsync(vm1);
        vm1.invoke(new SerializableRunnable("Wait to flow control messages") {

            public void run() {
                Wait.waitForCriterion(new WaitCriterion() {

                    public String description() {
                        return "Waiting for messages to be at least 2: " + observer.messageCount.get();
                    }

                    public boolean done() {
                        return observer.messageCount.get() >= 2;
                    }
                }, MAX_WAIT, 100, true);
                // Make sure no more messages show up
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    Assert.fail("interrupted", e);
                }
                assertEquals(2, observer.messageCount.get());
            }
        });
        try {
            vm0.invoke(new SerializableRunnable("check for in progress messages") {

                public void run() {
                    final DMStats stats = getSystem().getDMStats();
                    assertEquals(2, stats.getInitialImageMessagesInFlight());
                }
            });
        } catch (Exception e) {
            vm1.invoke(new SerializableRunnable("release flow control due to exception") {

                public void run() {
                    observer.allowMessages.countDown();
                }
            });
            throw e;
        }
        expectedEx = IgnoredException.addIgnoredException(InterruptedException.class.getName(), vm1);
        if (disconnect) {
            disconnect(vm1);
        } else {
            closeCache(vm1);
        }
        vm1.invoke(new SerializableRunnable("release flow control") {

            public void run() {
                observer.allowMessages.countDown();
            }
        });
        vm0.invoke(new SerializableRunnable("check for in progress messages") {

            public void run() {
                final DMStats stats = getSystem().getDMStats();
                Wait.waitForCriterion(new WaitCriterion() {

                    public boolean done() {
                        return stats.getInitialImageMessagesInFlight() == 0;
                    }

                    public String description() {
                        return "Timeout waiting for all initial image messages to be processed: " + stats.getInitialImageMessagesInFlight();
                    }
                }, MAX_WAIT, 100, true);
            }
        });
    } finally {
        if (expectedEx != null) {
            expectedEx.remove();
        }
    }
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Host(org.apache.geode.test.dunit.Host) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

Aggregations

IgnoredException (org.apache.geode.test.dunit.IgnoredException)142 Test (org.junit.Test)89 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)71 Region (org.apache.geode.cache.Region)46 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)46 VM (org.apache.geode.test.dunit.VM)43 Host (org.apache.geode.test.dunit.Host)38 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)34 AttributesFactory (org.apache.geode.cache.AttributesFactory)30 ForceReattemptException (org.apache.geode.internal.cache.ForceReattemptException)28 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)23 IOException (java.io.IOException)21 CacheClosedException (org.apache.geode.cache.CacheClosedException)21 LocalRegion (org.apache.geode.internal.cache.LocalRegion)20 PartitionOfflineException (org.apache.geode.cache.persistence.PartitionOfflineException)16 RMIException (org.apache.geode.test.dunit.RMIException)15 GatewaySender (org.apache.geode.cache.wan.GatewaySender)14 BucketRegion (org.apache.geode.internal.cache.BucketRegion)14 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)14 CacheXmlException (org.apache.geode.cache.CacheXmlException)12