Search in sources :

Example 71 with DistributedSystem

use of org.apache.geode.distributed.DistributedSystem in project geode by apache.

the class DeltaPropagationDUnitTest method createCache.

private void createCache(Properties props) throws Exception {
    DistributedSystem ds = getSystem(props);
    ds.disconnect();
    ds = getSystem(props);
    assertNotNull(ds);
    cache = CacheFactory.create(ds);
    assertNotNull(cache);
}
Also used : DistributedSystem(org.apache.geode.distributed.DistributedSystem)

Example 72 with DistributedSystem

use of org.apache.geode.distributed.DistributedSystem in project geode by apache.

the class OffHeapEvictionDUnitTest method createCache.

@Override
public void createCache() {
    try {
        Properties props = new Properties();
        DistributedSystem ds = getSystem(props);
        assertNotNull(ds);
        ds.disconnect();
        ds = getSystem(getDistributedSystemProperties());
        cache = CacheFactory.create(ds);
        assertNotNull(cache);
        LogWriterUtils.getLogWriter().info("cache= " + cache);
        LogWriterUtils.getLogWriter().info("cache closed= " + cache.isClosed());
        cache.getResourceManager().setEvictionOffHeapPercentage(85);
        ((GemFireCacheImpl) cache).getInternalResourceManager().getOffHeapMonitor().stopMonitoring(true);
        LogWriterUtils.getLogWriter().info("eviction= " + cache.getResourceManager().getEvictionOffHeapPercentage());
        LogWriterUtils.getLogWriter().info("critical= " + cache.getResourceManager().getCriticalOffHeapPercentage());
    } catch (Exception e) {
        Assert.fail("Failed while creating the cache", e);
    }
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) CacheException(org.apache.geode.cache.CacheException)

Example 73 with DistributedSystem

use of org.apache.geode.distributed.DistributedSystem in project geode by apache.

the class MapInterfaceJUnitTest method testLocalPutAll.

/**
   * Make sure putAll works on Scope.LOCAL (see bug 35087)
   */
@Test
public void testLocalPutAll() {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    DistributedSystem ds = DistributedSystem.connect(props);
    Cache cache = null;
    Region region = null;
    AttributesFactory factory = null;
    try {
        cache = CacheFactory.create(ds);
        factory = new AttributesFactory();
        factory.setScope(Scope.LOCAL);
        region = cache.createRegion("testingRegion", factory.create());
    } catch (Exception e) {
        throw new AssertionError(" failed due to ", e);
    }
    HashMap m = new HashMap();
    m.put("aKey", "aValue");
    m.put("bKey", "bValue");
    region.putAll(m);
    assertEquals("aValue", region.get("aKey"));
    assertEquals("bValue", region.get("bKey"));
    for (int i = 0; i < 100; i++) {
        region.put(new Integer(i), new Integer(i));
    }
    assertEquals(new Integer(50), region.get(new Integer(50)));
    region.localClear();
    assertEquals(null, region.get(new Integer(50)));
    region.close();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    try {
        region = cache.createRegion("testingRegion", factory.create());
    } catch (Exception e) {
        throw new AssertionError(" failed in creating region due to ", e);
    }
    boolean exceptionOccurred = false;
    try {
        region.localClear();
    } catch (UnsupportedOperationException e) {
        exceptionOccurred = true;
    }
    if (!exceptionOccurred) {
        fail(" exception did not occur when it was supposed to occur");
    }
    region.close();
    cache.close();
    ds.disconnect();
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) HashMap(java.util.HashMap) Region(org.apache.geode.cache.Region) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) CacheWriterException(org.apache.geode.cache.CacheWriterException) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 74 with DistributedSystem

use of org.apache.geode.distributed.DistributedSystem in project geode by apache.

the class MapInterfaceJUnitTest method testBeforeRegionClearCallBack.

@Test
public void testBeforeRegionClearCallBack() {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    DistributedSystem ds = DistributedSystem.connect(props);
    Cache cache = null;
    Region region = null;
    AttributesFactory factory = null;
    try {
        cache = CacheFactory.create(ds);
        factory = new AttributesFactory();
        factory.setScope(Scope.LOCAL);
        factory.setCacheWriter(new CacheWriterAdapter() {

            @Override
            public void beforeRegionClear(RegionEvent event) throws CacheWriterException {
                synchronized (this) {
                    this.notify();
                    MapInterfaceJUnitTest.this.hasBeenNotified = true;
                }
            }
        });
        region = cache.createRegion("testingRegion", factory.create());
        DoesClear doesClear = new DoesClear(region);
        new Thread(doesClear).start();
        synchronized (this) {
            if (!this.hasBeenNotified) {
                this.wait(3000);
            }
        }
        if (!this.hasBeenNotified) {
            fail(" beforeRegionClear call back did not come");
        }
    } catch (Exception e) {
        throw new AssertionError(" failed due to ", e);
    }
    for (int i = 0; i < 100; i++) {
        region.put(new Integer(i), new Integer(i));
    }
    assertEquals(new Integer(50), region.get(new Integer(50)));
    region.localClear();
    assertEquals(null, region.get(new Integer(50)));
    region.close();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setDataPolicy(DataPolicy.REPLICATE);
    try {
        region = cache.createRegion("testingRegion", factory.create());
    } catch (Exception e) {
        throw new AssertionError(" failed in creating region due to ", e);
    }
    boolean exceptionOccurred = false;
    try {
        region.localClear();
    } catch (UnsupportedOperationException e) {
        exceptionOccurred = true;
    }
    if (!exceptionOccurred) {
        fail(" exception did not occur when it was supposed to occur");
    }
    region.close();
    cache.close();
    ds.disconnect();
}
Also used : CacheWriterAdapter(org.apache.geode.cache.util.CacheWriterAdapter) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) RegionEvent(org.apache.geode.cache.RegionEvent) CacheWriterException(org.apache.geode.cache.CacheWriterException) AttributesFactory(org.apache.geode.cache.AttributesFactory) Region(org.apache.geode.cache.Region) Cache(org.apache.geode.cache.Cache) CacheWriterException(org.apache.geode.cache.CacheWriterException) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 75 with DistributedSystem

use of org.apache.geode.distributed.DistributedSystem in project geode by apache.

the class PartitionedRegionSingleHopWithServerGroupDUnitTest method createClientWith3PoolLocator.

public static void createClientWith3PoolLocator(String host, int port0, String group1, String group2, String group3) {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    PartitionedRegionSingleHopWithServerGroupDUnitTest test = new PartitionedRegionSingleHopWithServerGroupDUnitTest();
    DistributedSystem ds = test.getSystem(props);
    cache = CacheFactory.create(ds);
    assertNotNull(cache);
    CacheServerTestUtil.disableShufflingOfEndpoints();
    Pool p1, p2, p3;
    try {
        p1 = PoolManager.createFactory().addLocator(host, port0).setServerGroup(group1).setPingInterval(250).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1).setReadTimeout(2000).setSocketBufferSize(1000).setMinConnections(6).setMaxConnections(10).setRetryAttempts(3).create(PR_NAME);
        p2 = PoolManager.createFactory().addLocator(host, port0).setServerGroup(group2).setPingInterval(250).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1).setReadTimeout(2000).setSocketBufferSize(1000).setMinConnections(6).setMaxConnections(10).setRetryAttempts(3).create(PR_NAME2);
        p3 = PoolManager.createFactory().addLocator(host, port0).setServerGroup(group3).setPingInterval(250).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1).setReadTimeout(2000).setSocketBufferSize(1000).setMinConnections(6).setMaxConnections(10).setRetryAttempts(3).create(PR_NAME3);
    } finally {
        CacheServerTestUtil.enableShufflingOfEndpoints();
    }
    createColocatedRegionsInClientCacheWithDiffPool(p1.getName(), p2.getName(), p3.getName());
}
Also used : Pool(org.apache.geode.cache.client.Pool) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem)

Aggregations

DistributedSystem (org.apache.geode.distributed.DistributedSystem)250 Properties (java.util.Properties)102 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)65 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)61 Test (org.junit.Test)59 Cache (org.apache.geode.cache.Cache)55 AttributesFactory (org.apache.geode.cache.AttributesFactory)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)30 Region (org.apache.geode.cache.Region)24 IOException (java.io.IOException)20 CacheServer (org.apache.geode.cache.server.CacheServer)20 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)20 InternalCache (org.apache.geode.internal.cache.InternalCache)16 IgnoredException (org.apache.geode.test.dunit.IgnoredException)16 ArrayList (java.util.ArrayList)15 LogWriter (org.apache.geode.LogWriter)15 DistributedMember (org.apache.geode.distributed.DistributedMember)15 LocalRegion (org.apache.geode.internal.cache.LocalRegion)15 RegionAttributes (org.apache.geode.cache.RegionAttributes)14 Pool (org.apache.geode.cache.client.Pool)14