Search in sources :

Example 1 with RegionService

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

the class ClientCacheFactoryJUnitTest method test003DPmultiplePool.

/**
   * Make sure if we have more than one pool that we do not have a default
   */
@Test
public void test003DPmultiplePool() throws Exception {
    Properties dsProps = new Properties();
    dsProps.setProperty(MCAST_PORT, "0");
    DistributedSystem ds = DistributedSystem.connect(dsProps);
    PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 7777).create("p7");
    PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 6666).create("p6");
    this.cc = new ClientCacheFactory().create();
    GemFireCacheImpl gfc = (GemFireCacheImpl) this.cc;
    assertEquals(true, gfc.isClient());
    Pool defPool = gfc.getDefaultPool();
    assertEquals(null, defPool);
    // exists that is not multiuser enabled
    try {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        RegionService cc = this.cc.createAuthenticatedView(suProps);
        fail("expected IllegalStateException");
    } catch (IllegalStateException ignore) {
    }
    // however we should be to to create it by configuring a pool
    {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        Pool pool = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), CacheServer.DEFAULT_PORT).setMultiuserAuthentication(true).create("pool1");
        RegionService cc = this.cc.createAuthenticatedView(suProps, pool.getName());
        ProxyCache pc = (ProxyCache) cc;
        UserAttributes ua = pc.getUserAttributes();
        Pool proxyDefPool = ua.getPool();
        assertEquals(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT)), proxyDefPool.getServers());
        assertEquals(true, proxyDefPool.getMultiuserAuthentication());
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ProxyCache(org.apache.geode.cache.client.internal.ProxyCache) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) RegionService(org.apache.geode.cache.RegionService) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) UserAttributes(org.apache.geode.cache.client.internal.UserAttributes) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with RegionService

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

the class ClientCacheFactoryJUnitTest method test002DPsinglePool.

/**
   * Make sure if we have a single pool that it will be used as the default
   */
@Test
public void test002DPsinglePool() throws Exception {
    Properties dsProps = new Properties();
    dsProps.setProperty(MCAST_PORT, "0");
    DistributedSystem ds = DistributedSystem.connect(dsProps);
    Pool p = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 7777).create("singlePool");
    this.cc = new ClientCacheFactory().create();
    GemFireCacheImpl gfc = (GemFireCacheImpl) this.cc;
    assertEquals(true, gfc.isClient());
    Pool defPool = gfc.getDefaultPool();
    assertEquals(p, defPool);
    // exists that is not multiuser enabled
    try {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        RegionService cc = this.cc.createAuthenticatedView(suProps);
        fail("expected IllegalStateException");
    } catch (IllegalStateException ignore) {
    }
    // however we should be to to create it by configuring a pool
    {
        Properties suProps = new Properties();
        suProps.setProperty("user", "foo");
        Pool pool = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), CacheServer.DEFAULT_PORT).setMultiuserAuthentication(true).create("pool1");
        RegionService cc = this.cc.createAuthenticatedView(suProps, pool.getName());
        ProxyCache pc = (ProxyCache) cc;
        UserAttributes ua = pc.getUserAttributes();
        Pool proxyDefPool = ua.getPool();
        assertEquals(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT)), proxyDefPool.getServers());
        assertEquals(true, proxyDefPool.getMultiuserAuthentication());
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ProxyCache(org.apache.geode.cache.client.internal.ProxyCache) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) RegionService(org.apache.geode.cache.RegionService) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) InternalDistributedSystem(org.apache.geode.distributed.internal.InternalDistributedSystem) UserAttributes(org.apache.geode.cache.client.internal.UserAttributes) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 3 with RegionService

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

the class MemoryAllocatorImpl method getRegionLiveChunks.

/**
   * Returns a possibly empty list that contains all the Chunks used by regions.
   */
private List<OffHeapStoredObject> getRegionLiveChunks() {
    ArrayList<OffHeapStoredObject> result = new ArrayList<OffHeapStoredObject>();
    RegionService gfc = GemFireCacheImpl.getInstance();
    if (gfc != null) {
        Iterator<Region<?, ?>> rootIt = gfc.rootRegions().iterator();
        while (rootIt.hasNext()) {
            Region<?, ?> rr = rootIt.next();
            getRegionLiveChunks(rr, result);
            Iterator<Region<?, ?>> srIt = rr.subregions(true).iterator();
            while (srIt.hasNext()) {
                getRegionLiveChunks(srIt.next(), result);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) LocalRegion(org.apache.geode.internal.cache.LocalRegion) BucketRegion(org.apache.geode.internal.cache.BucketRegion) Region(org.apache.geode.cache.Region) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RegionService(org.apache.geode.cache.RegionService)

Example 4 with RegionService

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

the class ClientCacheFactoryJUnitTest method test005SecureUserDefaults.

@Test
public void test005SecureUserDefaults() throws Exception {
    Properties suProps = new Properties();
    suProps.setProperty("user", "foo");
    GemFireCacheImpl gfc = (GemFireCacheImpl) new ClientCacheFactory().setPoolMultiuserAuthentication(true).create();
    this.cc = gfc;
    RegionService cc1 = this.cc.createAuthenticatedView(suProps);
    assertEquals(true, gfc.isClient());
    Properties dsProps = this.cc.getDistributedSystem().getProperties();
    assertEquals("0", dsProps.getProperty(MCAST_PORT));
    assertEquals("", dsProps.getProperty(LOCATORS));
    Pool defPool = gfc.getDefaultPool();
    assertEquals("DEFAULT", defPool.getName());
    assertEquals(new ArrayList(), defPool.getLocators());
    assertEquals(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT)), defPool.getServers());
    assertEquals(true, defPool.getMultiuserAuthentication());
    // make sure we can create another secure user cache
    RegionService cc2 = this.cc.createAuthenticatedView(suProps);
    assertEquals(true, gfc.isClient());
    assertEquals("0", dsProps.getProperty(MCAST_PORT));
    assertEquals("", dsProps.getProperty(LOCATORS));
    defPool = gfc.getDefaultPool();
    assertEquals("DEFAULT", defPool.getName());
    assertEquals(new ArrayList(), defPool.getLocators());
    assertEquals(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT)), defPool.getServers());
    assertEquals(true, defPool.getMultiuserAuthentication());
    if (cc1 == cc2) {
        fail("expected two different secure user caches");
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) RegionService(org.apache.geode.cache.RegionService) Properties(java.util.Properties) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

RegionService (org.apache.geode.cache.RegionService)4 InetSocketAddress (java.net.InetSocketAddress)3 Properties (java.util.Properties)3 GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)3 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)3 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 ProxyCache (org.apache.geode.cache.client.internal.ProxyCache)2 UserAttributes (org.apache.geode.cache.client.internal.UserAttributes)2 DistributedSystem (org.apache.geode.distributed.DistributedSystem)2 InternalDistributedSystem (org.apache.geode.distributed.internal.InternalDistributedSystem)2 Region (org.apache.geode.cache.Region)1 BucketRegion (org.apache.geode.internal.cache.BucketRegion)1 LocalRegion (org.apache.geode.internal.cache.LocalRegion)1 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)1