Search in sources :

Example 86 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory in project geode by apache.

the class SlowRecDUnitTest method testSizeDisconnect.

/**
   * Make sure that exceeding the queue size limit causes a disconnect.
   */
@Test
public void testSizeDisconnect() throws Exception {
    final String expected = "org.apache.geode.internal.tcp.ConnectionException: Forced disconnect sent to" + "||java.io.IOException: Broken pipe";
    final String addExpected = "<ExpectedException action=add>" + expected + "</ExpectedException>";
    final String removeExpected = "<ExpectedException action=remove>" + expected + "</ExpectedException>";
    final AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_NO_ACK);
    final Region r = createRootRegion("slowrec", factory.create());
    final DM dm = getSystem().getDistributionManager();
    final DMStats stats = dm.getStats();
    // set others before vm0 connects
    final Set others = dm.getOtherDistributionManagerIds();
    // create receiver in vm0 with queuing enabled
    Properties p = new Properties();
    p.setProperty(ASYNC_DISTRIBUTION_TIMEOUT, "5");
    // 1 meg
    p.setProperty(ASYNC_MAX_QUEUE_SIZE, "1");
    doCreateOtherVm(p, false);
    final Object key = "key";
    // .1M async-max-queue-size should give us 10 of these 100K
    final int VALUE_SIZE = 1024 * 100;
    // msgs before queue full
    final byte[] value = new byte[VALUE_SIZE];
    int count = 0;
    forceQueuing(r);
    long queuedMsgs = stats.getAsyncQueuedMsgs();
    long queueSize = stats.getAsyncQueueSize();
    getCache().getLogger().info(addExpected);
    try {
        while (stats.getAsyncQueueSizeExceeded() == 0 && stats.getAsyncQueueTimeouts() == 0) {
            r.put(key, value);
            count++;
            if (stats.getAsyncQueueSize() > 0) {
                queuedMsgs = stats.getAsyncQueuedMsgs();
                queueSize = stats.getAsyncQueueSize();
            }
            if (count > 100) {
                fail("should have exceeded max-queue-size by now");
            }
        }
        LogWriterUtils.getLogWriter().info("After " + count + " " + VALUE_SIZE + " byte puts slowrec mode kicked in but the queue filled when its size reached " + queueSize + " with " + queuedMsgs + " msgs");
        // make sure we lost a connection to vm0
        WaitCriterion ev = new WaitCriterion() {

            public boolean done() {
                return dm.getOtherDistributionManagerIds().size() <= others.size() && stats.getAsyncQueueSize() == 0;
            }

            public String description() {
                return "waiting for connection loss";
            }
        };
        Wait.waitForCriterion(ev, 30 * 1000, 200, true);
    } finally {
        forceQueueFlush();
        getCache().getLogger().info(removeExpected);
    }
    assertEquals(others, dm.getOtherDistributionManagerIds());
    assertEquals(0, stats.getAsyncQueueSize());
}
Also used : DMStats(org.apache.geode.distributed.internal.DMStats) AttributesFactory(org.apache.geode.cache.AttributesFactory) Set(java.util.Set) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) Region(org.apache.geode.cache.Region) DM(org.apache.geode.distributed.internal.DM) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 87 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory in project geode by apache.

the class RemoveAllMultiVmDUnitTest method createMirroredRegion.

// end of createCache
public static void createMirroredRegion() {
    try {
        AttributesFactory factory = new AttributesFactory();
        factory.setDataPolicy(DataPolicy.REPLICATE);
        factory.setScope(Scope.DISTRIBUTED_ACK);
        RegionAttributes attr = factory.create();
        mirroredRegion = cache.createRegion("mirrored", attr);
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheException(org.apache.geode.cache.CacheException)

Example 88 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory in project geode by apache.

the class DistributedSystemDUnitTest method testIsolatedDistributedSystem.

@Test
public void testIsolatedDistributedSystem() throws Exception {
    Properties config = createLonerConfig();
    InternalDistributedSystem system = getSystem(config);
    // make sure isolated distributed system can still create a cache and region
    Cache cache = CacheFactory.create(system);
    Region region = cache.createRegion(getUniqueName(), new AttributesFactory().create());
    region.put("test", "value");
    assertThat(region.get("test")).isEqualTo("value");
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) Region(org.apache.geode.cache.Region) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) MembershipTest(org.apache.geode.test.junit.categories.MembershipTest) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 89 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory in project geode by apache.

the class DistTXDebugDUnitTest method createPR.

public static void createPR(String partitionedRegionName, Integer redundancy, Integer localMaxMemory, Integer totalNumBuckets, Object colocatedWith, Boolean isPartitionResolver, Boolean concurrencyChecks) {
    PartitionAttributesFactory<String, String> paf = new PartitionAttributesFactory();
    paf.setRedundantCopies(redundancy);
    if (localMaxMemory != null) {
        paf.setLocalMaxMemory(localMaxMemory);
    }
    if (totalNumBuckets != null) {
        paf.setTotalNumBuckets(totalNumBuckets);
    }
    if (colocatedWith != null) {
        paf.setColocatedWith((String) colocatedWith);
    }
    if (isPartitionResolver) {
        paf.setPartitionResolver(new CustomerIDPartitionResolver("CustomerIDPartitionResolver"));
    }
    PartitionAttributes<String, String> prAttr = paf.create();
    AttributesFactory<String, String> attr = new AttributesFactory();
    attr.setPartitionAttributes(prAttr);
    attr.setConcurrencyChecksEnabled(concurrencyChecks);
    assertNotNull(basicGetCache());
    Region<String, String> pr = basicGetCache().createRegion(partitionedRegionName, attr.create());
    assertNotNull(pr);
    LogWriterUtils.getLogWriter().info("Partitioned Region " + partitionedRegionName + " created Successfully :" + pr.toString());
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CustomerIDPartitionResolver(org.apache.geode.internal.cache.execute.CustomerIDPartitionResolver)

Example 90 with AttributesFactory

use of org.apache.geode.cache.AttributesFactory in project geode by apache.

the class DistTXDebugDUnitTest method createRR.

public static void createRR(String replicatedRegionName, boolean empty) {
    AttributesFactory af = new AttributesFactory();
    af.setScope(Scope.DISTRIBUTED_ACK);
    if (empty) {
        af.setDataPolicy(DataPolicy.EMPTY);
    } else {
        af.setDataPolicy(DataPolicy.REPLICATE);
    }
    // Region rr = basicGetCache().createRegion(replicatedRegionName,
    // af.create());
    Region rr = basicGetCache().createRegion(replicatedRegionName, af.create());
    assertNotNull(rr);
    LogWriterUtils.getLogWriter().info("Replicated Region " + replicatedRegionName + " created Successfully :" + rr.toString());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion)

Aggregations

AttributesFactory (org.apache.geode.cache.AttributesFactory)1156 Region (org.apache.geode.cache.Region)565 Test (org.junit.Test)550 RegionAttributes (org.apache.geode.cache.RegionAttributes)471 PartitionAttributesFactory (org.apache.geode.cache.PartitionAttributesFactory)468 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)356 VM (org.apache.geode.test.dunit.VM)304 Host (org.apache.geode.test.dunit.Host)288 Properties (java.util.Properties)244 CacheException (org.apache.geode.cache.CacheException)243 Cache (org.apache.geode.cache.Cache)229 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)206 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)201 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)199 LocalRegion (org.apache.geode.internal.cache.LocalRegion)173 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)156 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)139 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)129 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)126 IgnoredException (org.apache.geode.test.dunit.IgnoredException)125