Search in sources :

Example 16 with PoolImpl

use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.

the class ClientServerForceInvalidateDUnitTest method createClientCache.

public static void createClientCache(String h, int port1, int port2, boolean empty, boolean concurrenctChecksEnabled) throws Exception {
    AbstractRegionMap.FORCE_INVALIDATE_EVENT = true;
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    Cache cache = new ClientServerForceInvalidateDUnitTest().createCacheV(props);
    PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(h, port1).addServer(h, port2).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768).setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000).create("ClientServerForceInvalidateDUnitTestPool");
    RegionFactory<String, String> factory = cache.createRegionFactory();
    if (empty) {
        factory.setDataPolicy(DataPolicy.EMPTY);
        factory.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL));
    } else {
        factory.setDataPolicy(DataPolicy.NORMAL);
    }
    factory.setPoolName(p.getName());
    factory.setConcurrencyChecksEnabled(concurrenctChecksEnabled);
    region1 = factory.create(REGION_NAME1);
    region1.registerInterest("ALL_KEYS", InterestResultPolicy.NONE, false, false);
    region1.getAttributesMutator().addCacheListener(new ClientListener());
    assertNotNull(region1);
    with().pollDelay(1, TimeUnit.MILLISECONDS).pollInterval(1, TimeUnit.SECONDS).await().atMost(60, TimeUnit.SECONDS).until(() -> poolReady(p));
}
Also used : ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) Cache(org.apache.geode.cache.Cache) SubscriptionAttributes(org.apache.geode.cache.SubscriptionAttributes)

Example 17 with PoolImpl

use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.

the class ClientServerMiscDUnitTest method testCCPDestroyOnLastDestroyRegion.

/**
   * Test two regions: notify by subscription is true. Both the regions have registered interest in
   * all the keys. Destroy region1 on the client. It should reach the server , kill the region on
   * the server , propagate it to the interested clients , but it should keep CacheClient Proxy
   * alive. Destroy Region2 . It should reach server , close conenction proxy , destroy the region2
   * on the server , remove the cache client proxy from the cache client notifier & propagate it to
   * the clients. Then create third region and verify that no CacheClientProxy is created on server
   */
@Test
public void testCCPDestroyOnLastDestroyRegion() throws Exception {
    PORT1 = initServerCache(true);
    PoolImpl pool = (PoolImpl) createClientCache(NetworkUtils.getServerHostName(Host.getHost(0)), PORT1);
    destroyRegion1();
    // pause(5000);
    server1.invoke(() -> ClientServerMiscDUnitTest.verifyCacheClientProxyOnServer(new String(REGION_NAME1)));
    Connection conn = pool.acquireConnection();
    assertNotNull(conn);
    assertEquals(1, pool.getConnectedServerCount());
    assertEquals(false, pool.isDestroyed());
    destroyRegion2();
    assertEquals(false, pool.isDestroyed());
    destroyPRRegion();
    assertEquals(false, pool.isDestroyed());
    pool.destroy();
    assertEquals(true, pool.isDestroyed());
    // pause(5000);
    server1.invoke(() -> ClientServerMiscDUnitTest.verifyNoCacheClientProxyOnServer());
    try {
        getCache().createRegion(REGION_NAME2, attrs);
        fail("expected IllegalStateException");
    } catch (IllegalStateException expected) {
    }
}
Also used : Connection(org.apache.geode.cache.client.internal.Connection) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 18 with PoolImpl

use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.

the class ClientServerMiscDUnitTest method testInvalidatesPropagateOnRegionHavingNoPool.

/**
   * Create cache, create pool, notify-by-subscription=false, create a region and on client and on
   * server. Do not attach pool to region , populate some entries on region both on client and
   * server. Update the entries on server the client. The client should not have entry invalidate.
   */
@Test
public void testInvalidatesPropagateOnRegionHavingNoPool() throws Exception {
    // start server first
    PORT1 = initServerCache(false);
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new ClientServerMiscDUnitTest().createCache(props);
    String host = NetworkUtils.getServerHostName(server1.getHost());
    PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host, PORT1).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768).setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000).create("testInvalidatesPropagateOnRegionHavingNoPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    // factory.setPoolName(p.getName());
    attrs = factory.create();
    final Region region1 = getCache().createRegion(REGION_NAME1, attrs);
    final Region region2 = getCache().createRegion(REGION_NAME2, attrs);
    assertNotNull(region1);
    assertNotNull(region2);
    pool = p;
    conn = pool.acquireConnection();
    assertNotNull(conn);
    populateCache();
    server1.invoke(() -> ClientServerMiscDUnitTest.put());
    Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
        Object val = region1.getEntry(k1).getValue();
        return k1.equals(val);
    });
    Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
        Object val = region1.getEntry(k2).getValue();
        return k2.equals(val);
    });
    Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
        Object val = region2.getEntry(k1).getValue();
        return k1.equals(val);
    });
    Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> {
        Object val = region2.getEntry(k2).getValue();
        return k2.equals(val);
    });
// assertIndexDetailsEquals(region2.getEntry(k2).getValue(), k2);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test)

Example 19 with PoolImpl

use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.

the class ClientServerMiscDUnitTest method _createClientCache.

public static Pool _createClientCache(String h, boolean empty, int... ports) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    Cache cache = new ClientServerMiscDUnitTest().createCacheV(props);
    ClientServerMiscDUnitTest.static_cache = cache;
    PoolFactory poolFactory = PoolManager.createFactory();
    PoolImpl p = (PoolImpl) addServers(poolFactory, h, ports).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(1000).setSocketBufferSize(32768).setMinConnections(3).setSubscriptionRedundancy(-1).setPingInterval(2000).create("ClientServerMiscDUnitTestPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    if (empty) {
        factory.setDataPolicy(DataPolicy.EMPTY);
    }
    factory.setPoolName(p.getName());
    attrs = factory.create();
    Region region1 = cache.createRegion(REGION_NAME1, attrs);
    Region region2 = cache.createRegion(REGION_NAME2, attrs);
    Region prRegion = cache.createRegion(PR_REGION_NAME, attrs);
    assertNotNull(region1);
    assertNotNull(region2);
    assertNotNull(prRegion);
    pool = p;
    // conn = pool.acquireConnection();
    // assertNotNull(conn);
    // TODO does this WaitCriterion actually help?
    WaitCriterion wc = new WaitCriterion() {

        String excuse;

        public boolean done() {
            try {
                conn = pool.acquireConnection();
                if (conn == null) {
                    excuse = "acquireConnection returned null?";
                    return false;
                }
                return true;
            } catch (NoAvailableServersException e) {
                excuse = "Cannot find a server: " + e;
                return false;
            }
        }

        public String description() {
            return excuse;
        }
    };
    Wait.waitForCriterion(wc, 60 * 1000, 1000, true);
    return p;
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) PartitionAttributesFactory(org.apache.geode.cache.PartitionAttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) NoAvailableServersException(org.apache.geode.cache.client.NoAvailableServersException) LocalRegion(org.apache.geode.internal.cache.LocalRegion) Region(org.apache.geode.cache.Region) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) Cache(org.apache.geode.cache.Cache)

Example 20 with PoolImpl

use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.

the class ClearPropagationDUnitTest method acquireConnectionsAndDestroyRegion.

public static void acquireConnectionsAndDestroyRegion(String host) {
    try {
        Region r1 = cache.getRegion(Region.SEPARATOR + REGION_NAME);
        assertNotNull(r1);
        String poolName = r1.getAttributes().getPoolName();
        assertNotNull(poolName);
        PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
        assertNotNull(pool);
        Connection conn1 = pool.acquireConnection(new ServerLocation(host, PORT2));
        assertNotNull(conn1);
        assertEquals(PORT2, conn1.getServer().getPort());
        ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
        srp.destroyRegionOnForTestsOnly(conn1, new EventID(new byte[] { 1 }, 1, 1), null);
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("while setting acquireConnections  " + ex);
    }
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) Connection(org.apache.geode.cache.client.internal.Connection) Region(org.apache.geode.cache.Region) EventID(org.apache.geode.internal.cache.EventID) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CacheException(org.apache.geode.cache.CacheException)

Aggregations

PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)91 Properties (java.util.Properties)43 AttributesFactory (org.apache.geode.cache.AttributesFactory)40 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)39 Region (org.apache.geode.cache.Region)30 RegionAttributes (org.apache.geode.cache.RegionAttributes)29 Test (org.junit.Test)17 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)16 IOException (java.io.IOException)14 Pool (org.apache.geode.cache.client.Pool)14 VM (org.apache.geode.test.dunit.VM)14 Host (org.apache.geode.test.dunit.Host)13 CacheSerializableRunnable (org.apache.geode.cache30.CacheSerializableRunnable)12 LocalRegion (org.apache.geode.internal.cache.LocalRegion)11 WaitCriterion (org.apache.geode.test.dunit.WaitCriterion)11 CacheException (org.apache.geode.cache.CacheException)10 SerializableRunnable (org.apache.geode.test.dunit.SerializableRunnable)9 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)9 NoAvailableServersException (org.apache.geode.cache.client.NoAvailableServersException)8 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)8