Search in sources :

Example 36 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class SecurityTestUtil method createClientCache.

public static ClientCache createClientCache(String username, String password, int serverPort) {
    Properties props = new Properties();
    props.setProperty(UserPasswordAuthInit.USER_NAME, username);
    props.setProperty(UserPasswordAuthInit.PASSWORD, password);
    props.setProperty(SECURITY_CLIENT_AUTH_INIT, UserPasswordAuthInit.class.getName());
    props.setProperty(LOCATORS, "");
    props.setProperty(MCAST_PORT, "0");
    ClientCache cache = new ClientCacheFactory(props).setPoolSubscriptionEnabled(true).addPoolServer("localhost", serverPort).create();
    return cache;
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) Properties(java.util.Properties) UserPasswordAuthInit(org.apache.geode.security.templates.UserPasswordAuthInit) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 37 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class ClientServerCCEDUnitTest method createDurableClientRegion.

// For durable client QRM testing we need a backup queue (redundancy=1) and
// durable attributes. We also need to invoke readyForEvents()
private void createDurableClientRegion(final VM vm, final String regionName, final int port1, final int port2, final boolean ccEnabled) {
    SerializableCallable createRegion = new SerializableCallable() {

        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(NetworkUtils.getServerHostName(vm.getHost()), port1);
            cf.addPoolServer(NetworkUtils.getServerHostName(vm.getHost()), port2);
            cf.setPoolSubscriptionEnabled(true);
            cf.setPoolSubscriptionRedundancy(1);
            // bug #50683 - secondary durable queue retains all GC messages
            cf.set(DURABLE_CLIENT_ID, "" + vm.getPid());
            cf.set(DURABLE_CLIENT_TIMEOUT, "" + 200);
            cf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            ClientCache cache = getClientCache(cf);
            ClientRegionFactory crf = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY);
            crf.setConcurrencyChecksEnabled(ccEnabled);
            TestRegion = (LocalRegion) crf.create(regionName);
            TestRegion.registerInterestRegex(".*", InterestResultPolicy.KEYS_VALUES, true, true);
            cache.readyForEvents();
            return null;
        }
    };
    vm.invoke(createRegion);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) ClientCache(org.apache.geode.cache.client.ClientCache) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 38 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class ClientServerCCEDUnitTest method createClientRegion.

private void createClientRegion(final VM vm, final String regionName, final int port, final boolean ccEnabled, final ClientRegionShortcut clientRegionShortcut, final boolean registerInterest) {
    SerializableCallable createRegion = new SerializableCallable() {

        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(NetworkUtils.getServerHostName(vm.getHost()), port);
            if (registerInterest) {
                cf.setPoolSubscriptionEnabled(true);
            }
            cf.set(LOG_LEVEL, LogWriterUtils.getDUnitLogLevel());
            ClientCache cache = getClientCache(cf);
            ClientRegionFactory crf = cache.createClientRegionFactory(clientRegionShortcut);
            crf.setConcurrencyChecksEnabled(ccEnabled);
            crf.setStatisticsEnabled(true);
            TestRegion = (LocalRegion) crf.create(regionName);
            if (registerInterest) {
                TestRegion.registerInterestRegex(".*", InterestResultPolicy.KEYS_VALUES, false, true);
            }
            return null;
        }
    };
    vm.invoke(createRegion);
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) ClientCache(org.apache.geode.cache.client.ClientCache) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 39 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class CacheServerTestUtil method createClientCache.

private void createClientCache(Properties props, ClientCacheFactory ccf) throws Exception {
    DistributedSystem ds = getSystem(props);
    assertNotNull(ds);
    ds.disconnect();
    ClientCache cc = ccf.create();
    setSystem(props, cc.getDistributedSystem());
    cache = (Cache) cc;
    assertNotNull(cache);
    expected = IgnoredException.addIgnoredException("java.net.ConnectionException||java.net.SocketException");
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) DistributedSystem(org.apache.geode.distributed.DistributedSystem)

Example 40 with ClientCache

use of org.apache.geode.cache.client.ClientCache in project geode by apache.

the class PdxQueryDUnitTest method testPutAllWithIndexes.

/**
   * This test creates 3 cache servers with a PR and one client which puts some PDX values in PR and
   * runs a query. This was failing randomly in a POC.
   */
@Test
public void testPutAllWithIndexes() {
    final String name = "testRegion";
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    final Properties config = new Properties();
    config.setProperty("locators", "localhost[" + DistributedTestUtils.getDUnitLocatorPort() + "]");
    // Start server
    vm0.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Cache cache = new CacheFactory(config).create();
            AttributesFactory factory = new AttributesFactory();
            PartitionAttributesFactory prfactory = new PartitionAttributesFactory();
            prfactory.setRedundantCopies(0);
            factory.setPartitionAttributes(prfactory.create());
            cache.createRegionFactory(factory.create()).create(name);
            try {
                startCacheServer(0, false);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
            // Create Index on empty region
            try {
                cache.getQueryService().createIndex("myFuncIndex", "intId", "/" + name);
            } catch (Exception e) {
                Assert.fail("index creation failed", e);
            }
        }
    });
    // Start server
    vm1.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Cache cache = new CacheFactory(config).create();
            AttributesFactory factory = new AttributesFactory();
            PartitionAttributesFactory prfactory = new PartitionAttributesFactory();
            prfactory.setRedundantCopies(0);
            factory.setPartitionAttributes(prfactory.create());
            cache.createRegionFactory(factory.create()).create(name);
            try {
                startCacheServer(0, false);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
        }
    });
    // Start server
    vm2.invoke(new CacheSerializableRunnable("Create Bridge Server") {

        public void run2() throws CacheException {
            Cache cache = new CacheFactory(config).create();
            AttributesFactory factory = new AttributesFactory();
            PartitionAttributesFactory prfactory = new PartitionAttributesFactory();
            prfactory.setRedundantCopies(0);
            factory.setPartitionAttributes(prfactory.create());
            cache.createRegionFactory(factory.create()).create(name);
            try {
                startCacheServer(0, false);
            } catch (Exception ex) {
                Assert.fail("While starting CacheServer", ex);
            }
        }
    });
    // Create client region
    final int port = vm0.invoke(() -> PdxQueryDUnitTest.getCacheServerPort());
    final String host0 = NetworkUtils.getServerHostName(vm2.getHost());
    vm3.invoke(new CacheSerializableRunnable("Create region") {

        public void run2() throws CacheException {
            Properties config = new Properties();
            config.setProperty("mcast-port", "0");
            ClientCache cache = new ClientCacheFactory(config).addPoolServer(host0, port).setPoolPRSingleHopEnabled(true).setPoolSubscriptionEnabled(true).create();
            AttributesFactory factory = new AttributesFactory();
            cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(name);
        }
    });
    vm3.invoke(new CacheSerializableRunnable("putAll() test") {

        @Override
        public void run2() throws CacheException {
            try {
                ClientCache cache = new ClientCacheFactory().create();
                Region region = cache.getRegion(name);
                QueryService queryService = cache.getQueryService();
                String k;
                for (int x = 0; x < 285; x++) {
                    k = Integer.valueOf(x).toString();
                    PortfolioPdx v = new PortfolioPdx(x, x);
                    region.put(k, v);
                }
                Query q = queryService.newQuery("SELECT DISTINCT * from /" + name + " WHERE ID = 2");
                SelectResults qResult = (SelectResults) q.execute();
                for (Object o : qResult.asList()) {
                    System.out.println("o = " + o);
                }
            } catch (Exception e) {
                Assert.fail("Querying failed: ", e);
            }
        }
    });
    Invoke.invokeInEveryVM(DistributedTestCase.class, "disconnectFromDS");
// }
}
Also used : Query(org.apache.geode.cache.query.Query) CacheException(org.apache.geode.cache.CacheException) Host(org.apache.geode.test.dunit.Host) PortfolioPdx(org.apache.geode.cache.query.data.PortfolioPdx) ClientCache(org.apache.geode.cache.client.ClientCache) Properties(java.util.Properties) CacheException(org.apache.geode.cache.CacheException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) SelectResults(org.apache.geode.cache.query.SelectResults) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) QueryService(org.apache.geode.cache.query.QueryService) VM(org.apache.geode.test.dunit.VM) Region(org.apache.geode.cache.Region) CacheFactory(org.apache.geode.cache.CacheFactory) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

ClientCache (org.apache.geode.cache.client.ClientCache)115 Test (org.junit.Test)74 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)73 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)67 Region (org.apache.geode.cache.Region)65 VM (org.apache.geode.test.dunit.VM)43 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)42 Host (org.apache.geode.test.dunit.Host)40 SecurityTest (org.apache.geode.test.junit.categories.SecurityTest)31 QueryService (org.apache.geode.cache.query.QueryService)27 SelectResults (org.apache.geode.cache.query.SelectResults)26 SecurityTestUtil.createClientCache (org.apache.geode.security.SecurityTestUtil.createClientCache)25 SecurityTestUtil.createProxyRegion (org.apache.geode.security.SecurityTestUtil.createProxyRegion)23 CacheServer (org.apache.geode.cache.server.CacheServer)22 Cache (org.apache.geode.cache.Cache)20 CacheException (org.apache.geode.cache.CacheException)15 PortfolioPdx (org.apache.geode.cache.query.data.PortfolioPdx)13 IOException (java.io.IOException)12 Properties (java.util.Properties)12 IgnoredException (org.apache.geode.test.dunit.IgnoredException)12