Search in sources :

Example 26 with PoolImpl

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

the class HAEventIdPropagationDUnitTest method createClientCache.

/** function to create client cache * */
public static void createClientCache(String hostName, Integer port1) throws Exception {
    int PORT1 = port1.intValue();
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, "0");
    props.setProperty(LOCATORS, "");
    new HAEventIdPropagationDUnitTest().createCache(props);
    AttributesFactory factory = new AttributesFactory();
    PoolImpl pi = (PoolImpl) ClientServerTestCase.configureConnectionPool(factory, hostName, new int[] { PORT1 }, true, -1, 2, null);
    factory.setScope(Scope.DISTRIBUTED_ACK);
    CacheListener clientListener = new HAEventIdPropagationListenerForClient();
    factory.setCacheListener(clientListener);
    RegionAttributes attrs = factory.create();
    cache.createRegion(REGION_NAME, attrs);
    Region region = cache.getRegion(Region.SEPARATOR + REGION_NAME);
    assertNotNull(region);
    region.registerInterest("ALL_KEYS", InterestResultPolicy.NONE);
    System.out.println("KKKKKK:[" + pi.getName() + "]");
    ;
    PoolImpl p2 = (PoolImpl) PoolManager.find("testPool");
    System.out.println("QQQQ:" + p2);
    pool = pi;
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Region(org.apache.geode.cache.Region) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CacheListener(org.apache.geode.cache.CacheListener)

Example 27 with PoolImpl

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

the class DestroyEntryPropagationDUnitTest method testVerifyDestroyNotReceivedBySender.

/**
   * This tests whether the destroy are received by the sender or not if there are situation of
   * Interest List fail over
   */
// GEODE-897: random port, time sensitive, waitForCriterion, 2 minute
@Category(FlakyTest.class)
// timeouts, eats exception (1 fixed)
@Test
public void testVerifyDestroyNotReceivedBySender() {
    final int maxWaitTime = Integer.getInteger(WAIT_PROPERTY, WAIT_DEFAULT).intValue();
    // First create entries on both servers via the two client
    vm2.invoke(() -> DestroyEntryPropagationDUnitTest.createEntriesK1andK2());
    vm3.invoke(() -> DestroyEntryPropagationDUnitTest.createEntriesK1andK2());
    vm2.invoke(() -> DestroyEntryPropagationDUnitTest.registerKey1());
    vm3.invoke(() -> DestroyEntryPropagationDUnitTest.registerKey1());
    // Induce fail over of InterestList Endpoint to Server 2 by killing server1
    vm0.invoke(() -> DestroyEntryPropagationDUnitTest.killServer(new Integer(PORT1)));
    // Wait for 10 seconds to allow fail over. This would mean that Interest
    // has failed over to Server2.
    vm2.invoke(new CacheSerializableRunnable("Wait for server on port1 to be dead") {

        public void run2() throws CacheException {
            Region r = cache.getRegion(REGION_NAME);
            try {
                // Used in the case where we don't have a LiveServerMonitorThread
                r.put("ping", "pong1");
            } catch (CacheWriterException itsOK) {
            }
            try {
                // Used in the case where we don't have a LiveServerMonitorThread
                r.put("ping", "pong1");
            } catch (CacheWriterException itsOK) {
            }
            String poolName = r.getAttributes().getPoolName();
            assertNotNull(poolName);
            final PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
            assertNotNull(pool);
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    return pool.getConnectedServerCount() != 2;
                }

                public String description() {
                    return null;
                }
            };
            Wait.waitForCriterion(ev, maxWaitTime, 200, true);
        }
    });
    // Start Server1 again so that both clients1 & Client 2 will establish
    // connection to server1 too.
    vm0.invoke(() -> DestroyEntryPropagationDUnitTest.startServer(new Integer(PORT1)));
    vm2.invoke(new CacheSerializableRunnable("Wait for server on port1 to spring to life") {

        public void run2() throws CacheException {
            Region r = cache.getRegion(REGION_NAME);
            String poolName = r.getAttributes().getPoolName();
            assertNotNull(poolName);
            final PoolImpl pool = (PoolImpl) PoolManager.find(poolName);
            assertNotNull(pool);
            WaitCriterion ev = new WaitCriterion() {

                public boolean done() {
                    return pool.getConnectedServerCount() == 2;
                }

                public String description() {
                    return null;
                }
            };
            Wait.waitForCriterion(ev, maxWaitTime, 200, true);
        }
    });
    // Do a destroy on Server1 via Connection object from client1.
    // Client1 should not receive updated value while client2 should receive
    vm2.invoke(() -> acquireConnectionsAndDestroyEntriesK1andK2());
    // pause(10000);
    // Check if both the puts ( on key1 & key2 ) have reached the servers
    vm0.invoke(() -> DestroyEntryPropagationDUnitTest.verifyEntriesAreDestroyed());
    vm1.invoke(() -> DestroyEntryPropagationDUnitTest.verifyEntriesAreDestroyed());
    vm2.invoke(() -> DestroyEntryPropagationDUnitTest.verifyNoDestroyEntryInSender());
}
Also used : WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) CacheSerializableRunnable(org.apache.geode.cache30.CacheSerializableRunnable) CacheException(org.apache.geode.cache.CacheException) Region(org.apache.geode.cache.Region) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) CacheWriterException(org.apache.geode.cache.CacheWriterException) Category(org.junit.experimental.categories.Category) FlakyTest(org.apache.geode.test.junit.categories.FlakyTest) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 28 with PoolImpl

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

the class DestroyEntryPropagationDUnitTest method acquireConnectionsAndDestroyEntriesK1andK2.

private void acquireConnectionsAndDestroyEntriesK1andK2() {
    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 conn = pool.acquireConnection();
        final Connection conn1;
        if (conn.getServer().getPort() != PORT2) {
            // Ensure we have a server with the proper port
            conn1 = pool.acquireConnection();
        } else {
            conn1 = conn;
        }
        assertNotNull(conn1);
        assertEquals(PORT2, conn1.getServer().getPort());
        ServerRegionProxy srp = new ServerRegionProxy(Region.SEPARATOR + REGION_NAME, pool);
        srp.destroyOnForTestsOnly(conn1, "key1", null, Operation.DESTROY, new EventIDHolder(new EventID(new byte[] { 1 }, 100000, 1)), null);
        srp.destroyOnForTestsOnly(conn1, "key2", null, Operation.DESTROY, new EventIDHolder(new EventID(new byte[] { 1 }, 100000, 2)), null);
    } catch (Exception ex) {
        throw new AssertionError("Failed while setting acquireConnectionsAndDestroyEntry  ", ex);
    }
}
Also used : ServerRegionProxy(org.apache.geode.cache.client.internal.ServerRegionProxy) EventIDHolder(org.apache.geode.internal.cache.EventIDHolder) 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) CacheWriterException(org.apache.geode.cache.CacheWriterException)

Example 29 with PoolImpl

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

the class DurableClientBug39997DUnitTest method testNoServerAvailableOnStartup.

@Test
public void testNoServerAvailableOnStartup() {
    Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    final String hostName = NetworkUtils.getServerHostName(host);
    final int port = AvailablePortHelper.getRandomAvailableTCPPort();
    vm0.invoke(new SerializableRunnable("create cache") {

        public void run() {
            getSystem(getClientProperties());
            PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(hostName, port).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).create("DurableClientReconnectDUnitTestPool");
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.LOCAL);
            factory.setPoolName(p.getName());
            Cache cache = getCache();
            Region region1 = cache.createRegion("region", factory.create());
            cache.readyForEvents();
            try {
                region1.registerInterest("ALL_KEYS");
                fail("Should have received an exception trying to register interest");
            } catch (NoSubscriptionServersAvailableException expected) {
            // this is expected
            }
        }
    });
    vm1.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            AttributesFactory factory = new AttributesFactory();
            factory.setScope(Scope.DISTRIBUTED_ACK);
            cache.createRegion("region", factory.create());
            CacheServer server = cache.addCacheServer();
            server.setPort(port);
            try {
                server.start();
            } catch (IOException e) {
                Assert.fail("couldn't start server", e);
            }
        }
    });
    vm0.invoke(new SerializableRunnable() {

        public void run() {
            Cache cache = getCache();
            final Region region = cache.getRegion("region");
            Wait.waitForCriterion(new WaitCriterion() {

                public String description() {
                    return "Wait for register interest to succeed";
                }

                public boolean done() {
                    try {
                        region.registerInterest("ALL_KEYS");
                    } catch (NoSubscriptionServersAvailableException e) {
                        return false;
                    }
                    return true;
                }
            }, 30000, 1000, true);
        }
    });
}
Also used : SerializableRunnable(org.apache.geode.test.dunit.SerializableRunnable) Host(org.apache.geode.test.dunit.Host) IOException(java.io.IOException) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) AttributesFactory(org.apache.geode.cache.AttributesFactory) WaitCriterion(org.apache.geode.test.dunit.WaitCriterion) VM(org.apache.geode.test.dunit.VM) NoSubscriptionServersAvailableException(org.apache.geode.cache.NoSubscriptionServersAvailableException) Region(org.apache.geode.cache.Region) CacheServer(org.apache.geode.cache.server.CacheServer) Cache(org.apache.geode.cache.Cache) ClientSubscriptionTest(org.apache.geode.test.junit.categories.ClientSubscriptionTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 30 with PoolImpl

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

the class DurableClientReconnectDUnitTest method createCacheClientAndConnectToSingleServer.

private void createCacheClientAndConnectToSingleServer(String host, int redundancyLevel) {
    try {
        final String durableClientId = "DurableClientReconnectDUnitTest_client";
        // keep the client alive for 60 seconds
        final int durableClientTimeout = 60;
        Properties props = getClientDistributedSystemProperties(durableClientId, durableClientTimeout);
        instance = new DurableClientReconnectDUnitTest();
        instance.createCache(props);
        PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host, PORT1.intValue()).setSubscriptionEnabled(true).setReadTimeout(10000).setSubscriptionRedundancy(redundancyLevel).create("DurableClientReconnectDUnitTestPool");
        AttributesFactory factory = new AttributesFactory();
        factory.setScope(Scope.LOCAL);
        factory.setPoolName(p.getName());
        RegionAttributes attrs = factory.create();
        Region r = cache.createRegion(REGION_NAME, attrs);
        assertNotNull(r);
        pool = p;
        conn = pool.acquireConnection();
        assertNotNull(conn);
        cache.readyForEvents();
    } catch (Exception e) {
        Assert.fail("test failed due to ", e);
    }
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Region(org.apache.geode.cache.Region) ConfigurationProperties(org.apache.geode.distributed.ConfigurationProperties) Properties(java.util.Properties) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) SocketException(java.net.SocketException) IgnoredException(org.apache.geode.test.dunit.IgnoredException)

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