Search in sources :

Example 11 with PoolFactory

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

the class CacheServerMaxConnectionsJUnitTest method createProxyAndRegionForClient.

/**
   * Initializes proxy object and creates region for client
   */
private void createProxyAndRegionForClient() {
    // props.setProperty("retryAttempts", "0");
    PoolFactory pf = PoolManager.createFactory();
    pf.addServer("localhost", PORT);
    pf.setMinConnections(0);
    pf.setPingInterval(10000);
    pf.setThreadLocalConnections(true);
    pf.setReadTimeout(2000);
    pf.setSocketBufferSize(32768);
    proxy = (PoolImpl) pf.create("junitPool");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.DISTRIBUTED_ACK);
    factory.setPoolName("junitPool");
    RegionAttributes attrs = factory.createRegionAttributes();
    cache.createVMRegion(regionName, attrs);
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes)

Example 12 with PoolFactory

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

the class DeltaPropagationDUnitTest method testBug40165ClientReconnects.

@Test
public void testBug40165ClientReconnects() throws Exception {
    PORT1 = ((Integer) VM0.invoke(() -> DeltaPropagationDUnitTest.createServerCache(HARegionQueue.HA_EVICTION_POLICY_MEMORY))).intValue();
    /**
     * 1. Create a cache server with slow dispatcher 2. Start a durable client with a custom cache
     * listener which shuts itself down as soon as it recieves a marker message. 3. Do some puts on
     * the server region 4. Let the dispatcher start dispatching 5. Verify that durable client is
     * disconnected as soon as it processes the marker. Server will retain its queue which has some
     * events (containing deltas) in it. 6. Restart the durable client without the self-destructing
     * listener. 7. Wait till the durable client processes all its events. 8. Verify that no deltas
     * are received by it.
     */
    // Step 0
    prepareDeltas();
    VM0.invoke(() -> DeltaPropagationDUnitTest.prepareDeltas());
    // Step 1
    try {
        VM0.invoke(() -> ConflationDUnitTest.setIsSlowStart("60000"));
        // Step 2
        String durableClientId = getName() + "_client";
        PoolFactory pf = PoolManager.createFactory();
        pf.addServer("localhost", PORT1).setSubscriptionEnabled(true).setSubscriptionAckInterval(1);
        ((PoolFactoryImpl) pf).getPoolAttributes();
        Properties properties = new Properties();
        properties.setProperty(MCAST_PORT, "0");
        properties.setProperty(LOCATORS, "");
        properties.setProperty(DURABLE_CLIENT_ID, durableClientId);
        properties.setProperty(DURABLE_CLIENT_TIMEOUT, String.valueOf(60));
        createDurableCacheClient(((PoolFactoryImpl) pf).getPoolAttributes(), regionName, properties, new Integer(DURABLE_CLIENT_LISTENER), Boolean.TRUE);
        // Step 3
        VM0.invoke(() -> DeltaPropagationDUnitTest.doPuts());
        // Step 4
        VM0.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
        // Step 5
        // verifyDurableClientDisconnected();
        Thread.sleep(5000);
        // Step 6
        createDurableCacheClient(((PoolFactoryImpl) pf).getPoolAttributes(), regionName, properties, new Integer(DURABLE_CLIENT_LISTENER), Boolean.FALSE);
        // Step 7
        waitForLastKey();
        // Step 8
        long fromDeltasOnClient = DeltaTestImpl.getFromDeltaInvokations().longValue();
        assertTrue("No deltas were to be received but received: " + fromDeltasOnClient, fromDeltasOnClient < 1);
    } finally {
        // Step 4
        VM0.invoke(() -> ConflationDUnitTest.unsetIsSlowStart());
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest) ConflationDUnitTest(org.apache.geode.internal.cache.tier.sockets.ConflationDUnitTest) Test(org.junit.Test)

Example 13 with PoolFactory

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

the class ClientConflationDUnitTest method createPool2.

private static void createPool2(String host, AttributesFactory factory, Integer port) {
    PoolFactory pf = PoolManager.createFactory();
    pf.addServer(host, port.intValue()).setSubscriptionEnabled(true).setThreadLocalConnections(true).setReadTimeout(10000).setSocketBufferSize(32768).setPingInterval(1000).setMinConnections(3).setSubscriptionRedundancy(-1);
    Pool pool = pf.create("superpoolish" + (poolNameCounter++));
    factory.setPoolName(pool.getName());
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) Pool(org.apache.geode.cache.client.Pool)

Example 14 with PoolFactory

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

the class ClientHealthMonitorJUnitTest method createProxyAndRegionForClient.

/**
   * Initializes proxy object and creates region for client
   * 
   */
private void createProxyAndRegionForClient() {
    try {
        // props.setProperty("retryAttempts", "5");
        PoolFactory pf = PoolManager.createFactory();
        proxy = (PoolImpl) pf.addServer("localhost", PORT).setThreadLocalConnections(true).setReadTimeout(10000).setPingInterval(10000).setMinConnections(0).create("junitPool");
        AttributesFactory factory = new AttributesFactory();
        factory.setScope(Scope.DISTRIBUTED_ACK);
        cache.createVMRegion(regionName, factory.createRegionAttributes());
    } catch (Exception ex) {
        ex.printStackTrace();
        fail("Failed to initialize client");
    }
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) AttributesFactory(org.apache.geode.cache.AttributesFactory) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException)

Example 15 with PoolFactory

use of org.apache.geode.cache.client.PoolFactory 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)

Aggregations

PoolFactory (org.apache.geode.cache.client.PoolFactory)66 Test (org.junit.Test)34 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)21 CacheServer (org.apache.geode.cache.server.CacheServer)16 Properties (java.util.Properties)15 AttributesFactory (org.apache.geode.cache.AttributesFactory)14 Host (org.apache.geode.test.dunit.Host)13 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)12 ClientSubscriptionTest (org.apache.geode.test.junit.categories.ClientSubscriptionTest)12 Cache (org.apache.geode.cache.Cache)11 Pool (org.apache.geode.cache.client.Pool)11 ConfigurationProperties (org.apache.geode.distributed.ConfigurationProperties)11 PoolFactoryImpl (org.apache.geode.internal.cache.PoolFactoryImpl)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)10 VM (org.apache.geode.test.dunit.VM)9 Region (org.apache.geode.cache.Region)8 EventID (org.apache.geode.internal.cache.EventID)8 IOException (java.io.IOException)7 ClientCache (org.apache.geode.cache.client.ClientCache)7 SerializableCallable (org.apache.geode.test.dunit.SerializableCallable)7