Search in sources :

Example 31 with AttributesFactory

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

the class CqQueryUsingPoolDUnitTest method getRegionAttributes.

/**
   * Returns region attributes for a <code>LOCAL</code> region
   */
protected RegionAttributes getRegionAttributes() {
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    return factory.createRegionAttributes();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory)

Example 32 with AttributesFactory

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

the class ClientToServerDeltaDUnitTest method createServerCache.

/*
   * create server cache
   */
public static Integer createServerCache(Boolean attachListener, Boolean isEmpty, Boolean clone, Boolean enableDelta) throws Exception {
    // for validation
    updates = 0;
    create = 0;
    firstUpdate = null;
    secondUpdate = null;
    error = false;
    Properties props = new Properties();
    props.setProperty(DELTA_PROPAGATION, enableDelta.toString());
    new ClientToServerDeltaDUnitTest().createCache(props);
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setConcurrencyChecksEnabled(true);
    if (isEmpty) {
        factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
        factory.setDataPolicy(DataPolicy.EMPTY);
    } else {
        factory.setDataPolicy(DataPolicy.REPLICATE);
    }
    factory.setCloningEnabled(clone);
    RegionAttributes attrs = factory.create();
    region = cache.createRegion(REGION_NAME, attrs);
    AttributesMutator am = region.getAttributesMutator();
    if (attachListener) {
        am.addCacheListener(new CacheListenerAdapter() {

            @Override
            public void afterCreate(EntryEvent event) {
                create++;
            }

            @Override
            public void afterUpdate(EntryEvent event) {
                switch(updates) {
                    case 0:
                        // first delta
                        validateUpdates(event, firstUpdate, "FIRST");
                        updates++;
                        break;
                    case 1:
                        // combine delta
                        validateUpdates(event, firstUpdate, "FIRST");
                        validateUpdates(event, secondUpdate, "SECOND");
                        updates++;
                        break;
                    default:
                        break;
                }
            }
        });
    } else if (!isEmpty) {
        am.addCacheListener(new CacheListenerAdapter() {

            @Override
            public void afterCreate(EntryEvent event) {
                switch(create) {
                    case 1:
                        validateUpdates(event, firstUpdate, "FIRST");
                        create++;
                        break;
                    case 2:
                        validateUpdates(event, secondUpdate, "SECOND");
                        create++;
                        break;
                    default:
                        create++;
                        break;
                }
            }
        });
    }
    CacheServer server = cache.addCacheServer();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    server.setPort(port);
    // ensures updates to be sent instead of invalidations
    server.setNotifyBySubscription(true);
    server.start();
    return new Integer(server.getPort());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) CacheListenerAdapter(org.apache.geode.cache.util.CacheListenerAdapter) RegionAttributes(org.apache.geode.cache.RegionAttributes) EntryEvent(org.apache.geode.cache.EntryEvent) CacheServer(org.apache.geode.cache.server.CacheServer) Properties(java.util.Properties) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes) AttributesMutator(org.apache.geode.cache.AttributesMutator)

Example 33 with AttributesFactory

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

the class CQListGIIDUnitTest method createClientCache.

public static void createClientCache(Integer port1, Integer port2, Integer port3, String rLevel, Boolean addListener) throws Exception {
    CacheServerTestUtil.disableShufflingOfEndpoints();
    String host = NetworkUtils.getIPLiteral();
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new CQListGIIDUnitTest().createCache(props);
    PoolFactory pf = PoolManager.createFactory();
    int endPointCount = 1;
    pf.addServer(host, port1);
    if (port2.intValue() != -1) {
        pf.addServer(host, port2);
        endPointCount++;
    }
    if (port3.intValue() != -1) {
        pf.addServer(host, port3);
        endPointCount++;
    }
    pf.setRetryAttempts(5);
    pf.setReadTimeout(2500);
    pf.setSocketBufferSize(32768);
    pf.setPingInterval(1000);
    pf.setMinConnections(endPointCount * 2);
    pf.setSubscriptionRedundancy(Integer.parseInt(rLevel));
    pf.setSubscriptionEnabled(true).create("clientPool");
    try {
        cache.getQueryService();
    } catch (Exception cqe) {
        Assert.fail("Failed to getCQService.", cqe);
    }
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setPoolName("clientPool");
    RegionAttributes attrs = factory.create();
    createRegion(regions[0], "root", attrs);
    createRegion(regions[1], "root", attrs);
    logger = cache.getLogger();
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) IOException(java.io.IOException) CacheException(org.apache.geode.cache.CacheException)

Example 34 with AttributesFactory

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

the class CQListGIIDUnitTest method createServerCache.

public static Integer createServerCache(String ePolicy, Integer cap) throws Exception {
    new CQListGIIDUnitTest().createCache(new Properties());
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    RegionAttributes attrs = factory.create();
    // cache.createRegion(regionName, attrs);
    createRegion(regions[0], "root", attrs);
    createRegion(regions[1], "root", attrs);
    Thread.sleep(2000);
    logger = cache.getLogger();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    CacheServer server1 = cache.addCacheServer();
    server1.setPort(port);
    server1.setNotifyBySubscription(true);
    if (ePolicy != null) {
        File overflowDirectory = new File("bsi_overflow_" + port);
        overflowDirectory.mkdir();
        DiskStoreFactory dsf = cache.createDiskStoreFactory();
        File[] dirs1 = new File[] { overflowDirectory };
        server1.getClientSubscriptionConfig().setEvictionPolicy(ePolicy);
        server1.getClientSubscriptionConfig().setCapacity(cap.intValue());
        // specify diskstore for this server
        server1.getClientSubscriptionConfig().setDiskStoreName(dsf.setDiskDirs(dirs1).create("bsi").getName());
    }
    server1.start();
    Thread.sleep(2000);
    return Integer.valueOf(server1.getPort());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) CacheServer(org.apache.geode.cache.server.CacheServer) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) File(java.io.File) DiskStoreFactory(org.apache.geode.cache.DiskStoreFactory)

Example 35 with AttributesFactory

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

the class DeltaToRegionRelationCQRegistrationDUnitTest method createClientCache2.

/*
   * create client cache and return's primary server location object (primary)
   */
public static Integer createClientCache2(String host1, String host2, Integer port1, Integer port2) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new DeltaToRegionRelationCQRegistrationDUnitTest().createCache(props);
    PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host1, port1.intValue()).addServer(host2, port2.intValue()).setThreadLocalConnections(true).setMinConnections(3).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setReadTimeout(10000).setSocketBufferSize(32768).create("DeltaToRegionRelationCQRegistrationTestPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.EMPTY);
    factory.setPoolName(p.getName());
    // region with empty data policy
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME1, attrs);
    factory.setDataPolicy(DataPolicy.NORMAL);
    attrs = factory.create();
    // region with non empty data policy
    cache.createRegion(REGION_NAME2, attrs);
    return new Integer(p.getPrimaryPort());
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) CqAttributesFactory(org.apache.geode.cache.query.CqAttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl)

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