Search in sources :

Example 76 with ClientCache

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

the class RollingUpgrade2DUnitTest method createClientRegion.

// Assumes a client cache is passed
public static void createClientRegion(GemFireCache cache, String regionName, ClientRegionShortcut shortcut) throws Exception {
    ClientRegionFactory rf = ((ClientCache) cache).createClientRegionFactory(shortcut);
    rf.create(regionName);
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) ClientRegionFactory(org.apache.geode.cache.client.ClientRegionFactory)

Example 77 with ClientCache

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

the class RegionCreateDestroyDUnitTest method testCreateDestroyReservedRegion.

// GEODE-1878
@Category(FlakyTest.class)
@Test
public void testCreateDestroyReservedRegion() throws InterruptedException {
    Cache serverCache = getCache();
    try {
        serverCache.createRegionFactory(RegionShortcut.REPLICATE).create(RESERVED_REGION_NAME);
        fail("Should have thrown an IllegalArgumentException");
    } catch (IllegalArgumentException arg) {
        assertEquals("Region names may not begin with a double-underscore: __ReservedRegion", arg.getMessage());
    }
    try {
        startServer(serverCache);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    try {
        client1.invoke(() -> {
            ClientCache cache = new ClientCacheFactory(createClientProperties()).setPoolSubscriptionEnabled(true).addPoolServer("localhost", serverPort).create();
            try {
                cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(RESERVED_REGION_NAME);
                fail("Should have thrown an IllegalArgumentException");
            } catch (IllegalArgumentException e) {
                assertEquals("Region names may not begin with a double-underscore: __ReservedRegion", e.getMessage());
            }
        });
    } catch (RMIException rmi) {
        rmi.getCause();
    }
}
Also used : RMIException(org.apache.geode.test.dunit.RMIException) IOException(java.io.IOException) ClientCache(org.apache.geode.cache.client.ClientCache) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Category(org.junit.experimental.categories.Category) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 78 with ClientCache

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

the class RegionCreateDestroyDUnitTest method testCreateDestroyValidRegion.

// GEODE-1922
@Category(FlakyTest.class)
@Test
public void testCreateDestroyValidRegion() throws InterruptedException {
    Cache serverCache = getCache();
    serverCache.createRegionFactory(RegionShortcut.REPLICATE).create(GOOD_REGION_NAME);
    try {
        startServer(serverCache);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    client1.invoke(() -> {
        ClientCache cache = new ClientCacheFactory(createClientProperties()).setPoolSubscriptionEnabled(true).addPoolServer("localhost", serverPort).create();
        Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(GOOD_REGION_NAME);
        region.destroyRegion();
        assertThat(region.isDestroyed()).isTrue();
    });
}
Also used : Region(org.apache.geode.cache.Region) IOException(java.io.IOException) ClientCache(org.apache.geode.cache.client.ClientCache) Cache(org.apache.geode.cache.Cache) ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) Category(org.junit.experimental.categories.Category) SecurityTest(org.apache.geode.test.junit.categories.SecurityTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest)

Example 79 with ClientCache

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

the class QueryDataInconsistencyDUnitTest method createProxyRegs.

private void createProxyRegs() {
    ClientCache cache = (ClientCache) CacheFactory.getAnyInstance();
    cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(repRegionName);
/*
     * cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create( PartitionedRegionName1);
     */
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache)

Example 80 with ClientCache

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

the class PdxQueryDUnitTest method testPdxInstanceNoFieldNoMethod.

/**
   * Test to query a field that is not present in the Pdx object Also the implicit method is absent
   * in the class
   * 
   * @throws CacheException
   */
@Test
public void testPdxInstanceNoFieldNoMethod() throws CacheException {
    final Host host = Host.getHost(0);
    final VM vm0 = host.getVM(0);
    final VM vm3 = host.getVM(3);
    final int numberOfEntries = 10;
    final String name = "/" + regionName;
    final String[] qs = { "select * from " + name + " where pdxStatus = 'active'", "select pdxStatus from " + name + " where id > 4" };
    // Start server1
    final int port1 = (Integer) vm0.invoke(new SerializableCallable("Create Server1") {

        @Override
        public Object call() throws Exception {
            Region r1 = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
            CacheServer server = getCache().addCacheServer();
            int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite();
            server.setPort(port);
            server.start();
            return port;
        }
    });
    // create client and load only version 1 objects with no pdxStatus field
    vm3.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            ClientCacheFactory cf = new ClientCacheFactory();
            cf.addPoolServer(NetworkUtils.getServerHostName(vm0.getHost()), port1);
            ClientCache cache = getClientCache(cf);
            Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(regionName);
            // Load version 1 objects
            for (int i = 0; i < numberOfEntries; i++) {
                PdxInstanceFactory pdxInstanceFactory = PdxInstanceFactoryImpl.newCreator("PdxVersionedNewPortfolio", false);
                pdxInstanceFactory.writeInt("id", i);
                pdxInstanceFactory.writeString("status", (i % 2 == 0 ? "active" : "inactive"));
                PdxInstance pdxInstance = pdxInstanceFactory.create();
                region.put("key-" + i, pdxInstance);
            }
            return null;
        }
    });
    // Version1 class loader
    vm3.invoke(new SerializableCallable("Create client") {

        @Override
        public Object call() throws Exception {
            // Load version 1 classloader
            QueryService remoteQueryService = null;
            // Execute query remotely
            try {
                remoteQueryService = getCache().getQueryService();
            } catch (Exception e) {
                Assert.fail("Failed to get QueryService.", e);
            }
            for (int i = 0; i < qs.length; i++) {
                try {
                    SelectResults sr = (SelectResults) remoteQueryService.newQuery(qs[i]).execute();
                    if (i == 1) {
                        assertEquals(5, sr.size());
                        for (Object o : sr) {
                            if (!(o instanceof Undefined)) {
                                fail("Result should be Undefined and not " + o.getClass());
                            }
                        }
                    } else {
                        assertEquals(0, sr.size());
                    }
                } catch (Exception e) {
                    Assert.fail("Failed executing " + qs[i], e);
                }
            }
            return null;
        }
    });
    Invoke.invokeInEveryVM(DistributedTestCase.class, "disconnectFromDS");
}
Also used : PdxInstanceFactory(org.apache.geode.pdx.PdxInstanceFactory) Undefined(org.apache.geode.cache.query.internal.Undefined) Host(org.apache.geode.test.dunit.Host) ClientCache(org.apache.geode.cache.client.ClientCache) CacheException(org.apache.geode.cache.CacheException) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory) SelectResults(org.apache.geode.cache.query.SelectResults) 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) CacheServer(org.apache.geode.cache.server.CacheServer) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) Test(org.junit.Test)

Aggregations

ClientCache (org.apache.geode.cache.client.ClientCache)112 Test (org.junit.Test)74 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)73 ClientCacheFactory (org.apache.geode.cache.client.ClientCacheFactory)65 Region (org.apache.geode.cache.Region)64 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)26 SelectResults (org.apache.geode.cache.query.SelectResults)25 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