Search in sources :

Example 21 with ClientCache

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

the class GFSnapshotDUnitTest method createAndStartClient.

private void createAndStartClient(final int locatorPort, final String serverHostName) {
    ClientCacheFactory clientCacheFactory = new ClientCacheFactory();
    clientCacheFactory.set("log-level", "config").addPoolLocator(serverHostName, locatorPort);
    ClientCache clientCache = clientCacheFactory.create();
    clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create("TestRegion");
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) ClientCacheFactory(org.apache.geode.cache.client.ClientCacheFactory)

Example 22 with ClientCache

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

the class GFSnapshotDUnitTest method testDataExportAndIterate.

@Test
public void testDataExportAndIterate() throws IOException, ClassNotFoundException {
    int locatorPort = AvailablePortHelper.getRandomAvailableTCPPort();
    String serverHostName = NetworkUtils.getServerHostName(host);
    Properties properties = configureCommonProperties(new Properties());
    locator.invoke("Start Locator", () -> configureAndStartLocator(locatorPort, serverHostName, properties));
    server.invoke("Start Server", () -> configureAndStartServer(locatorPort, serverHostName, properties));
    client.invoke("Start client", () -> {
        createAndStartClient(locatorPort, serverHostName);
        return null;
    });
    client.invoke("Populate data", () -> populateDataOnClient());
    String snapshotFilePath = server.invoke("Export data snapshot", () -> createSnapshot());
    client.invoke("Iterate over snapshot", () -> {
        ClientCache clientCache = ClientCacheFactory.getAnyInstance();
        clientCache.close();
        createAndStartClient(locatorPort, serverHostName);
        iterateOverSnapshot(snapshotFilePath);
    });
}
Also used : ClientCache(org.apache.geode.cache.client.ClientCache) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 23 with ClientCache

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

the class CompressionRegionConfigDUnitTest method putUsingClientVM.

/**
   * Performs a put operation on a client virtual machine.
   * 
   * @param vm a client.
   * @param key the key to put.
   * @param value the value to put.
   * @return the old value.
   */
private String putUsingClientVM(final VM vm, final String key, final String value) {
    return (String) vm.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            ClientCache cache = getClientCache(getClientCacheFactory(getLocatorPort()));
            Region<String, String> region = cache.getRegion(REGION_NAME);
            assertNotNull(region);
            return region.put(key, value);
        }
    });
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) ClientCache(org.apache.geode.cache.client.ClientCache)

Example 24 with ClientCache

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

the class CompressionRegionConfigDUnitTest method getUsingClientVM.

/**
   * Performs a get operation on a client.
   * 
   * @param vm a client.
   * @param key a region entry key.
   * @return the value.
   */
private String getUsingClientVM(final VM vm, final String key) {
    return (String) vm.invoke(new SerializableCallable() {

        @Override
        public Object call() throws Exception {
            ClientCache cache = getClientCache(getClientCacheFactory(getLocatorPort()));
            Region<String, String> region = cache.getRegion(REGION_NAME);
            assertNotNull(region);
            return region.get(key);
        }
    });
}
Also used : SerializableCallable(org.apache.geode.test.dunit.SerializableCallable) ClientCache(org.apache.geode.cache.client.ClientCache)

Example 25 with ClientCache

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

the class RegionCreateDestroyDUnitTest method testCreateInvalidRegion.

@Test
public void testCreateInvalidRegion() throws InterruptedException {
    Cache serverCache = getCache();
    try {
        serverCache.createRegionFactory(RegionShortcut.REPLICATE).create(BAD_REGION_NAME);
    } catch (IllegalArgumentException iae) {
        assertEquals("Region names may only be alphanumeric and may contain hyphens or underscores: Bad@Region", iae.getMessage());
    }
    try {
        startServer(serverCache);
    } catch (IOException e) {
        fail(e.getMessage());
    }
    client1.invoke(() -> {
        ClientCache cache = new ClientCacheFactory(createClientProperties()).setPoolSubscriptionEnabled(true).addPoolServer("localhost", serverPort).create();
        try {
            cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(BAD_REGION_NAME);
            fail("Should have thrown an IllegalArgumentException");
        } catch (IllegalArgumentException iae) {
            assertEquals("Region names may only be alphanumeric and may contain hyphens or underscores: Bad@Region", iae.getMessage());
        }
    });
}
Also used : 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) 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)

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