Search in sources :

Example 6 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl 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 7 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl 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 8 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class ClientCacheFactoryJUnitTest method test000Defaults.

@Test
public void test000Defaults() throws Exception {
    this.cc = new ClientCacheFactory().create();
    GemFireCacheImpl gfc = (GemFireCacheImpl) this.cc;
    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());
    ClientCache cc2 = new ClientCacheFactory().create();
    if (cc2 != this.cc) {
        fail("expected cc2 and cc to be == " + cc2 + this.cc);
    }
    try {
        new ClientCacheFactory().set(LOG_LEVEL, "severe").create();
        fail("expected create to fail");
    } catch (IllegalStateException expected) {
    }
    try {
        new ClientCacheFactory().addPoolLocator("127.0.0.1", 36666).create();
        fail("expected create to fail");
    } catch (IllegalStateException expected) {
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Properties(java.util.Properties) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 9 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class SelectStarQueryDUnitTest method testSelectStarQueryForPdxObjects.

@Test
public void testSelectStarQueryForPdxObjects() throws Exception {
    final Host host = Host.getHost(0);
    final VM server1 = host.getVM(0);
    final VM client = host.getVM(3);
    // create servers and regions
    final int port1 = startReplicatedCacheServer(server1);
    server1.invoke(new SerializableCallable("Set observer") {

        @Override
        public Object call() throws Exception {
            oldObserver = QueryObserverHolder.setInstance(new QueryResultTrackingObserver());
            return null;
        }
    });
    // create client
    client.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(getServerHostName(server1.getHost()), port1);
            ClientCache cache = getClientCache(cf);
            cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName);
            return null;
        }
    });
    // Update with serialized PortfolioPdx objects
    client.invoke(new SerializableCallable("Put objects") {

        @Override
        public Object call() throws Exception {
            Region r1 = getRootRegion(regName);
            for (int i = 0; i < 20; i++) {
                r1.put("key-" + i, new PortfolioPdx(i));
            }
            return null;
        }
    });
    // query remotely from client
    client.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            getLogWriter().info("Querying remotely from client");
            QueryService localQS = null;
            QueryService remoteQS = null;
            try {
                localQS = ((ClientCache) getCache()).getLocalQueryService();
                remoteQS = ((ClientCache) getCache()).getQueryService();
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            SelectResults res = null;
            SelectResults[][] sr = new SelectResults[1][2];
            for (int i = 0; i < queries.length; i++) {
                try {
                    res = (SelectResults) localQS.newQuery(queries[i]).execute();
                    sr[0][0] = res;
                    res = (SelectResults) remoteQS.newQuery(queries[i]).execute();
                    sr[0][1] = res;
                    CacheUtils.compareResultsOfWithAndWithoutIndex(sr);
                } catch (Exception e) {
                    fail("Error executing query: " + queries[i], e);
                }
                assertEquals(resultSize[i], res.size());
                if (i == 3) {
                    int cnt = ((Integer) res.iterator().next());
                    assertEquals(20, cnt);
                } else {
                    for (Object rs : res) {
                        if (rs instanceof StructImpl) {
                            for (Object obj : ((StructImpl) rs).getFieldValues()) {
                                if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
                                } else {
                                    fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + obj.getClass());
                                }
                            }
                        } else if (rs instanceof PortfolioPdx) {
                        } else {
                            fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
                        }
                    }
                }
            }
            return null;
        }
    });
    // verify if objects iterated by query are serialized
    server1.invoke(new SerializableCallable("Get observer") {

        @Override
        public Object call() throws Exception {
            QueryObserver observer = QueryObserverHolder.getInstance();
            assertTrue(QueryObserverHolder.hasObserver());
            assertTrue(observer instanceof QueryResultTrackingObserver);
            QueryResultTrackingObserver resultObserver = (QueryResultTrackingObserver) observer;
            assertTrue(resultObserver.isObjectSerialized());
            return null;
        }
    });
    // verify if objects returned by local server query are not serialized
    server1.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            QueryObserver observer = QueryObserverHolder.setInstance(new QueryResultTrackingObserver());
            QueryService qs = null;
            try {
                qs = getCache().getQueryService();
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            SelectResults res = null;
            for (int i = 0; i < queries.length; i++) {
                try {
                    res = (SelectResults) qs.newQuery(queries[i]).execute();
                } catch (Exception e) {
                    fail("Error executing query: " + queries[i], e);
                }
                assertEquals(resultSize[i], res.size());
                if (i == 3) {
                    int cnt = ((Integer) res.iterator().next());
                    assertEquals(20, cnt);
                } else {
                    for (Object rs : res) {
                        if (rs instanceof StructImpl) {
                            for (Object obj : ((StructImpl) rs).getFieldValues()) {
                                if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
                                } else {
                                    fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + obj.getClass());
                                }
                            }
                        } else if (rs instanceof PortfolioPdx) {
                        } else {
                            fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
                        }
                    }
                }
            }
            observer = QueryObserverHolder.getInstance();
            assertTrue(QueryObserverHolder.hasObserver());
            assertTrue(observer instanceof QueryResultTrackingObserver);
            QueryResultTrackingObserver resultObserver = (QueryResultTrackingObserver) observer;
            assertFalse(resultObserver.isObjectSerialized());
            QueryObserverHolder.setInstance(oldObserver);
            return null;
        }
    });
    // verify if Pdx instances are returned by local server query
    // if read-serialized is set true
    server1.invoke(new SerializableCallable("Query") {

        @Override
        public Object call() throws Exception {
            GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
            cache.setReadSerialized(true);
            QueryService qs = null;
            try {
                qs = getCache().getQueryService();
            } catch (Exception e) {
                fail("Exception getting query service ", e);
            }
            SelectResults res = null;
            for (int i = 0; i < queries.length; i++) {
                try {
                    res = (SelectResults) qs.newQuery(queries[i]).execute();
                } catch (Exception e) {
                    fail("Error executing query: " + queries[i], e);
                }
                assertEquals(resultSize[i], res.size());
                if (i == 3) {
                    int cnt = ((Integer) res.iterator().next());
                    assertEquals(20, cnt);
                } else {
                    for (Object rs : res) {
                        if (rs instanceof StructImpl) {
                            for (Object obj : ((StructImpl) rs).getFieldValues()) {
                                if (obj instanceof PdxInstance) {
                                } else {
                                    fail("Result objects for remote client query: " + queries[i] + " should be instance of PdxInstance and not " + obj.getClass());
                                }
                            }
                        } else if (rs instanceof PdxInstance) {
                        } else {
                            fail("Result objects for remote client query: " + queries[i] + " should be instance of PdxInstance and not " + rs.getClass());
                        }
                    }
                }
            }
            return null;
        }
    });
    closeCache(client);
    closeCache(server1);
}
Also used : PositionPdx(org.apache.geode.cache.query.data.PositionPdx) Host(org.apache.geode.test.dunit.Host) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) QueryObserver(org.apache.geode.cache.query.internal.QueryObserver) SelectResults(org.apache.geode.cache.query.SelectResults) StructImpl(org.apache.geode.cache.query.internal.StructImpl) PdxInstance(org.apache.geode.pdx.PdxInstance) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) Region(org.apache.geode.cache.Region) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 10 with GemFireCacheImpl

use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.

the class CacheXml66DUnitTest method testLOCAL_PERSISTENT_OVERFLOW.

@Test
public void testLOCAL_PERSISTENT_OVERFLOW() throws Exception {
    CacheCreation cache = new CacheCreation();
    RegionCreation root = (RegionCreation) cache.createRegion("cpolocal", "LOCAL_PERSISTENT_OVERFLOW");
    testXml(cache);
    GemFireCacheImpl c = (GemFireCacheImpl) getCache();
    Region r = c.getRegion("cpolocal");
    assertNotNull(r);
    RegionAttributes ra = r.getAttributes();
    assertEquals(DataPolicy.PERSISTENT_REPLICATE, ra.getDataPolicy());
    assertEquals(Scope.LOCAL, ra.getScope());
    assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes());
    assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, c.getResourceManager().getEvictionHeapPercentage(), 0);
}
Also used : RegionAttributes(org.apache.geode.cache.RegionAttributes) GemFireCacheImpl(org.apache.geode.internal.cache.GemFireCacheImpl) LocalRegion(org.apache.geode.internal.cache.LocalRegion) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) Region(org.apache.geode.cache.Region) DistributedRegion(org.apache.geode.internal.cache.DistributedRegion) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) RegionCreation(org.apache.geode.internal.cache.xmlcache.RegionCreation) Test(org.junit.Test)

Aggregations

GemFireCacheImpl (org.apache.geode.internal.cache.GemFireCacheImpl)213 Test (org.junit.Test)127 Region (org.apache.geode.cache.Region)86 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)55 LocalRegion (org.apache.geode.internal.cache.LocalRegion)54 PartitionedRegion (org.apache.geode.internal.cache.PartitionedRegion)51 VM (org.apache.geode.test.dunit.VM)49 DistributedRegion (org.apache.geode.internal.cache.DistributedRegion)47 Host (org.apache.geode.test.dunit.Host)42 ClientCacheCreation (org.apache.geode.internal.cache.xmlcache.ClientCacheCreation)40 RegionAttributes (org.apache.geode.cache.RegionAttributes)39 CacheCreation (org.apache.geode.internal.cache.xmlcache.CacheCreation)35 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)33 CacheException (org.apache.geode.cache.CacheException)32 RegionCreation (org.apache.geode.internal.cache.xmlcache.RegionCreation)32 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)31 Properties (java.util.Properties)24 AttributesFactory (org.apache.geode.cache.AttributesFactory)24 Cache (org.apache.geode.cache.Cache)23 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)23