Search in sources :

Example 41 with DistributedSystem

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

the class Bug33726JUnitTest method testAfterRegionCreate.

@Test
public void testAfterRegionCreate() {
    Properties props = new Properties();
    props.put(MCAST_PORT, "0");
    DistributedSystem ds = DistributedSystem.connect(props);
    AttributesFactory factory = new AttributesFactory();
    factory.setCacheListener(new TestCacheListener());
    Cache cache = null;
    try {
        cache = CacheFactory.create(ds);
        Region region = cache.createRegion("testRegion", factory.create());
        region.createSubregion("testSubRegion", factory.create());
    } catch (Exception e) {
        fail("Failed to create cache due to " + e);
        e.printStackTrace();
    }
    if (!testFlag()) {
        fail("After create sent although region was not initialized");
    }
}
Also used : Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 42 with DistributedSystem

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

the class Bug34583JUnitTest method testBunchOfInvalidEntries.

@Test
public void testBunchOfInvalidEntries() throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    DistributedSystem ds = DistributedSystem.connect(props);
    try {
        AttributesFactory factory = new AttributesFactory();
        Cache cache = null;
        cache = CacheFactory.create(ds);
        Region r = cache.createRegion("testRegion", factory.create());
        final int ENTRY_COUNT = 25000;
        {
            for (int i = 1; i <= ENTRY_COUNT; i++) {
                r.put("key" + i, "value" + i);
            }
        }
        {
            // make sure iterator works while values are valid
            Collection c = r.values();
            assertEquals(ENTRY_COUNT, c.size());
            Iterator it = c.iterator();
            int count = 0;
            while (it.hasNext()) {
                it.next();
                count++;
            }
            assertEquals(ENTRY_COUNT, count);
        }
        r.localInvalidateRegion();
        // now we expect iterator to stackOverflow if bug 34583
        {
            Collection c = r.values();
            assertEquals(0, c.size());
            Iterator it = c.iterator();
            int count = 0;
            while (it.hasNext()) {
                it.next();
                count++;
            }
            assertEquals(0, count);
        }
    } finally {
        ds.disconnect();
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) Iterator(java.util.Iterator) Region(org.apache.geode.cache.Region) Collection(java.util.Collection) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 43 with DistributedSystem

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

the class CacheAdvisorDUnitTest method getDistributionManagerId.

/**
   * Accessed via reflection. DO NOT REMOVE
   */
protected InternalDistributedMember getDistributionManagerId() {
    Cache cache = getCache();
    DistributedSystem ds = cache.getDistributedSystem();
    return ((InternalDistributedSystem) ds).getDistributionManager().getId();
}
Also used : DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) Cache(org.apache.geode.cache.Cache)

Example 44 with DistributedSystem

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

the class MyFunctionException method createCache.

private void createCache(Properties props) {
    try {
        DistributedSystem ds = getSystem(props);
        assertNotNull(ds);
        ds.disconnect();
        ds = getSystem(props);
        cache = CacheFactory.create(ds);
        LogWriterUtils.getLogWriter().info("Created Cache on peer");
        assertNotNull(cache);
        FunctionService.registerFunction(function);
    } catch (Exception e) {
        Assert.fail("DistributedRegionFunctionExecutionDUnitTest#createCache() Failed while creating the cache", e);
    }
}
Also used : InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) DistributedSystem(org.apache.geode.distributed.DistributedSystem) IgnoredException(org.apache.geode.test.dunit.IgnoredException) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) IOException(java.io.IOException) DistribuedRegionFunctionFunctionInvocationException(org.apache.geode.internal.cache.functions.DistribuedRegionFunctionFunctionInvocationException)

Example 45 with DistributedSystem

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

the class PRClientServerRegionFunctionExecutionFailoverDUnitTest method createServerWithLocator.

public int createServerWithLocator(String locator, boolean isAccessor, ArrayList commonAttrs) {
    Properties props = new Properties();
    props = new Properties();
    props.setProperty(LOCATORS, locator);
    DistributedSystem ds = getSystem(props);
    cache = new CacheFactory(props).create(ds);
    CacheServer server = cache.addCacheServer();
    int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    server.setPort(port);
    server.setHostnameForClients("localhost");
    try {
        server.start();
    } catch (IOException e) {
        Assert.fail("Failed to start server ", e);
    }
    PartitionAttributesFactory paf = new PartitionAttributesFactory();
    if (isAccessor) {
        paf.setLocalMaxMemory(0);
    }
    paf.setTotalNumBuckets(((Integer) commonAttrs.get(3)).intValue()).setRedundantCopies(((Integer) commonAttrs.get(2)).intValue());
    AttributesFactory attr = new AttributesFactory();
    attr.setPartitionAttributes(paf.create());
    region = cache.createRegion(regionName, attr.create());
    assertNotNull(region);
    LogWriterUtils.getLogWriter().info("Partitioned Region " + regionName + " created Successfully :" + region.toString());
    return port;
}
Also used : PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) CacheServer(org.apache.geode.cache.server.CacheServer) IOException(java.io.IOException) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) CacheFactory(org.apache.geode.cache.CacheFactory) 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