Search in sources :

Example 41 with AttributesFactory

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

the class WANTestBase method createReplicatedRegion.

public static void createReplicatedRegion(String regionName, String senderIds, Scope scope, DataPolicy policy, Boolean offHeap) {
    AttributesFactory fact = new AttributesFactory();
    if (senderIds != null) {
        StringTokenizer tokenizer = new StringTokenizer(senderIds, ",");
        while (tokenizer.hasMoreTokens()) {
            String senderId = tokenizer.nextToken();
            fact.addGatewaySenderId(senderId);
        }
    }
    fact.setDataPolicy(policy);
    fact.setScope(scope);
    fact.setOffHeap(offHeap);
    Region r = cache.createRegionFactory(fact.create()).create(regionName);
    assertNotNull(r);
}
Also used : StringTokenizer(java.util.StringTokenizer) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region)

Example 42 with AttributesFactory

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

the class ParallelGatewaySenderQueueOverflowDUnitTest method test_ValidateParallelGatewaySenderQueueAttributes_1.

/**
   * Test to validate that ParallelGatewaySenderQueue diskSynchronous attribute when persistence of
   * sender is enabled.
   */
@Ignore("TODO: test is disabled")
@Test
public void test_ValidateParallelGatewaySenderQueueAttributes_1() {
    Integer localLocPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
    Integer remoteLocPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, localLocPort));
    WANTestBase test = new WANTestBase();
    Properties props = test.getDistributedSystemProperties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "localhost[" + localLocPort + "]");
    InternalDistributedSystem ds = test.getSystem(props);
    cache = CacheFactory.create(ds);
    File directory = new File("TKSender" + "_disk_" + System.currentTimeMillis() + "_" + VM.getCurrentVMNum());
    directory.mkdir();
    File[] dirs1 = new File[] { directory };
    DiskStoreFactory dsf = cache.createDiskStoreFactory();
    dsf.setDiskDirs(dirs1);
    DiskStore diskStore = dsf.create("FORNY");
    GatewaySenderFactory fact = cache.createGatewaySenderFactory();
    // set parallel to true
    fact.setParallel(true);
    fact.setBatchConflationEnabled(true);
    fact.setBatchSize(200);
    fact.setBatchTimeInterval(300);
    // enable the persistence
    fact.setPersistenceEnabled(true);
    fact.setDiskSynchronous(true);
    fact.setDiskStoreName("FORNY");
    fact.setMaximumQueueMemory(200);
    fact.setAlertThreshold(1200);
    GatewayEventFilter myEventFilter1 = new MyGatewayEventFilter1();
    fact.addGatewayEventFilter(myEventFilter1);
    GatewayTransportFilter myStreamFilter1 = new MyGatewayTransportFilter1();
    fact.addGatewayTransportFilter(myStreamFilter1);
    GatewayTransportFilter myStreamFilter2 = new MyGatewayTransportFilter2();
    fact.addGatewayTransportFilter(myStreamFilter2);
    final IgnoredException exTKSender = IgnoredException.addIgnoredException("Could not connect");
    try {
        GatewaySender sender1 = fact.create("TKSender", 2);
        AttributesFactory factory = new AttributesFactory();
        factory.addGatewaySenderId(sender1.getId());
        factory.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
        Region region = cache.createRegionFactory(factory.create()).create("test_ValidateGatewaySenderAttributes");
        Set<GatewaySender> senders = cache.getGatewaySenders();
        assertEquals(senders.size(), 1);
        GatewaySender gatewaySender = senders.iterator().next();
        Set<RegionQueue> regionQueues = ((AbstractGatewaySender) gatewaySender).getQueues();
        assertEquals(regionQueues.size(), 1);
        RegionQueue regionQueue = regionQueues.iterator().next();
        assertEquals(true, regionQueue.getRegion().getAttributes().isDiskSynchronous());
    } finally {
        exTKSender.remove();
    }
}
Also used : GatewaySender(org.apache.geode.cache.wan.GatewaySender) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) WANTestBase(org.apache.geode.internal.cache.wan.WANTestBase) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) MyGatewayTransportFilter1(org.apache.geode.cache30.MyGatewayTransportFilter1) MyGatewayTransportFilter2(org.apache.geode.cache30.MyGatewayTransportFilter2) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) RegionQueue(org.apache.geode.internal.cache.RegionQueue) DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) MyGatewayEventFilter1(org.apache.geode.cache30.MyGatewayEventFilter1) GatewaySenderFactory(org.apache.geode.cache.wan.GatewaySenderFactory) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Region(org.apache.geode.cache.Region) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) GatewayTransportFilter(org.apache.geode.cache.wan.GatewayTransportFilter) AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) File(java.io.File) GatewayEventFilter(org.apache.geode.cache.wan.GatewayEventFilter) Ignore(org.junit.Ignore) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 43 with AttributesFactory

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

the class DiskDistributedNoAckAsyncOverflowRegionDUnitTest method getRegionAttributes.

protected RegionAttributes getRegionAttributes() {
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_NO_ACK);
    factory.setDiskStoreName(getCache().createDiskStoreFactory().setDiskDirs(getDiskDirs()).setTimeInterval(1000).setQueueSize(0).create(getUniqueName()).getName());
    factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(1, null, EvictionAction.OVERFLOW_TO_DISK));
    factory.setDiskSynchronous(false);
    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    return factory.create();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory)

Example 44 with AttributesFactory

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

the class DiskRegionDUnitTest method testBackup.

@Test
public void testBackup() throws Exception {
    final String name = this.getUniqueName();
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
    factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
    File d = new File("DiskRegions" + OSProcess.getId());
    d.mkdirs();
    DiskStoreFactory dsf = getCache().createDiskStoreFactory();
    dsf.setDiskDirs(new File[] { d });
    factory.setDiskSynchronous(true);
    DiskStore ds = dsf.create(name);
    factory.setDiskStoreName(ds.getName());
    int total = 10;
    {
        Region region = createRegion(name, factory.create());
        for (int i = 0; i < total; i++) {
            String s = String.valueOf(i);
            region.put(s, s);
        }
        region.put("foobar", "junk");
        region.localDestroy("foobar");
        region.put("foobar2", "junk");
        flush(region);
        region.localDestroy("foobar2");
        // test invalidate
        region.put("invalid", "invalid");
        flush(region);
        region.invalidate("invalid");
        flush(region);
        assertTrue(region.containsKey("invalid") && !region.containsValueForKey("invalid"));
        total++;
        // test local-invalidate
        region.put("localinvalid", "localinvalid");
        flush(region);
        region.localInvalidate("localinvalid");
        flush(region);
        assertTrue(region.containsKey("localinvalid") && !region.containsValueForKey("localinvalid"));
        total++;
        // test byte[] values
        region.put("byteArray", new byte[0]);
        flush(region);
        assertArrayEquals(new byte[0], region.get("byteArray"));
        total++;
        // test modification
        region.put("modified", "originalValue");
        flush(region);
        region.put("modified", "modified");
        flush(region);
        assertEquals("modified", region.get("modified"));
        total++;
        assertEquals(total, region.keySet().size());
    }
    // @todo need to do a close that does not remove disk files
    closeCache();
    getCache();
    {
        dsf = getCache().createDiskStoreFactory();
        dsf.setDiskDirs(new File[] { d });
        dsf.create(name);
        Region region = createRegion(name, factory.create());
        assertEquals(total, region.keySet().size());
        assertTrue(region.containsKey("invalid") && !region.containsValueForKey("invalid"));
        region.localDestroy("invalid");
        total--;
        assertTrue(region.containsKey("localinvalid") && !region.containsValueForKey("localinvalid"));
        region.localDestroy("localinvalid");
        total--;
        assertArrayEquals(new byte[0], region.get("byteArray"));
        region.localDestroy("byteArray");
        total--;
        assertEquals("modified", region.get("modified"));
        region.localDestroy("modified");
        total--;
    }
}
Also used : DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) DiskRegion(org.apache.geode.internal.cache.DiskRegion) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 45 with AttributesFactory

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

the class DiskRegionDUnitTest method testRemoteUpdates.

/**
   * Makes sure that updates from other VMs cause existing entries to be written to disk.
   */
@Test
public void testRemoteUpdates() throws Exception {
    final String name = this.getUniqueName();
    SerializableRunnable create = new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_NO_ACK);
            factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(2, null, EvictionAction.OVERFLOW_TO_DISK));
            File d = new File("DiskRegions" + OSProcess.getId());
            d.mkdirs();
            DiskStoreFactory dsf = getCache().createDiskStoreFactory();
            dsf.setDiskDirs(new File[] { d });
            DiskStore ds = dsf.create(name);
            factory.setDiskStoreName(ds.getName());
            createRegion(name, factory.create());
        }
    };
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    vm0.invoke(create);
    vm1.invoke(create);
    vm0.invoke(new CacheSerializableRunnable("Fill Region") {

        public void run2() throws CacheException {
            LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
            // DiskRegion dr = region.getDiskRegion();
            LRUStatistics lruStats = getLRUStats(region);
            int i;
            for (i = 0; lruStats.getEvictions() <= 0; i++) {
                region.put(new Integer(i), new short[250]);
            }
            assertTrue(i > 5);
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Update Region") {

        public void run2() throws CacheException {
            LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
            // LRUStatistics lruStats = getLRUStats(region);
            for (int i = 0; i < 10; i++) {
                region.put(new Integer(i), new int[250]);
            }
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Verify overflow") {

        public void run2() throws CacheException {
            LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
            // DiskRegion dr = region.getDiskRegion();
            final LRUStatistics lruStats = getLRUStats(region);
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    return lruStats.getEvictions() > 6;
                }

                public String description() {
                    return "waiting for evictions to exceed 6";
                }
            };
            Wait.waitForCriterion(ev, 5 * 1000, 200, true);
        // DiskRegionStats diskStats = dr.getStats();
        // assertTrue(diskStats.getWrites() > 6);
        }
    });
    vm0.invoke(new CacheSerializableRunnable("Populate with byte[]") {

        public void run2() throws CacheException {
            LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
            // LRUStatistics lruStats = getLRUStats(region);
            for (int i = 0; i < 10000; i++) {
                region.put(String.valueOf(i), String.valueOf(i).getBytes());
            }
        }
    });
    vm1.invoke(new CacheSerializableRunnable("Get with byte[]") {

        public void run2() throws CacheException {
            LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
            // LRUStatistics lruStats = getLRUStats(region);
            for (int i = 0; i < 10000; i++) {
                byte[] bytes = (byte[]) region.get(String.valueOf(i));
                assertEquals(String.valueOf(i), new String(bytes));
            }
        }
    });
}
Also used : CacheException(org.apache.geode.cache.CacheException) SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) LocalRegion(org.apache.geode.internal.cache.LocalRegion) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory) DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) LRUStatistics(org.apache.geode.internal.cache.lru.LRUStatistics) File(java.io.File) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

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