Search in sources :

Example 6 with PoolFactoryImpl

use of org.apache.geode.internal.cache.PoolFactoryImpl in project geode by apache.

the class LocatorLoadBalancingDUnitTest method testIntersectingServerGroups.

/**
   * Test that the locator balances load between three servers with intersecting server groups.
   * Server: 1 2 3 Groups: a a,b b
   *
   * @throws Exception
   */
@Test
public void testIntersectingServerGroups() throws Exception {
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    VM vm3 = host.getVM(3);
    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    String hostName = NetworkUtils.getServerHostName(vm0.getHost());
    vm0.invoke("Start Locator", () -> startLocator(hostName, locatorPort, ""));
    String locators = getLocatorString(host, locatorPort);
    int serverPort1 = vm1.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "a" }, locators));
    vm2.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "a", "b" }, locators));
    vm3.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "b" }, locators));
    PoolFactoryImpl pf = new PoolFactoryImpl(null);
    pf.addLocator(NetworkUtils.getServerHostName(host), locatorPort);
    pf.setMinConnections(12);
    pf.setSubscriptionEnabled(false);
    pf.setServerGroup("a");
    pf.setIdleTimeout(-1);
    startBridgeClient(pf.getPoolAttributes(), new String[] { REGION_NAME });
    waitForPrefilledConnections(12);
    vm1.invoke("Check Connection Count", () -> checkConnectionCount(6));
    vm2.invoke("Check Connection Count", () -> checkConnectionCount(6));
    vm3.invoke("Check Connection Count", () -> checkConnectionCount(0));
    LogWriterUtils.getLogWriter().info("pool1 prefilled");
    PoolFactoryImpl pf2 = (PoolFactoryImpl) PoolManager.createFactory();
    pf2.init(pf.getPoolAttributes());
    pf2.setServerGroup("b");
    PoolImpl pool2 = (PoolImpl) pf2.create("testPool2");
    waitForPrefilledConnections(12, "testPool2");
    // The load will not be perfect, because we created all of the connections
    // for group A first.
    vm1.invoke("Check Connection Count", () -> checkConnectionCount(6));
    vm2.invoke("Check Connection Count", () -> checkConnectionCount(9));
    vm3.invoke("Check Connection Count", () -> checkConnectionCount(9));
    LogWriterUtils.getLogWriter().info("pool2 prefilled");
    ServerLocation location1 = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort1);
    PoolImpl pool1 = (PoolImpl) PoolManager.getAll().get(POOL_NAME);
    Assert.assertEquals("a", pool1.getServerGroup());
    // Use up all of the pooled connections on pool1, and acquire 3 more
    for (int i = 0; i < 15; i++) {
        pool1.acquireConnection();
    }
    LogWriterUtils.getLogWriter().info("aquired 15 connections in pool1");
    // now the load should be equal
    vm1.invoke("Check Connection Count", () -> checkConnectionCount(9));
    vm2.invoke("Check Connection Count", () -> checkConnectionCount(9));
    vm3.invoke("Check Connection Count", () -> checkConnectionCount(9));
    // use up all of the pooled connections on pool2
    for (int i = 0; i < 12; i++) {
        pool2.acquireConnection();
    }
    LogWriterUtils.getLogWriter().info("aquired 12 connections in pool2");
    // interleave creating connections in both pools
    for (int i = 0; i < 6; i++) {
        pool1.acquireConnection();
        pool2.acquireConnection();
    }
    LogWriterUtils.getLogWriter().info("interleaved 6 connections from pool1 with 6 connections from pool2");
    // The load should still be balanced
    vm1.invoke("Check Connection Count", () -> checkConnectionCount(13));
    vm2.invoke("Check Connection Count", () -> checkConnectionCount(13));
    vm3.invoke("Check Connection Count", () -> checkConnectionCount(13));
}
Also used : ServerLocation(org.apache.geode.distributed.internal.ServerLocation) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 7 with PoolFactoryImpl

use of org.apache.geode.internal.cache.PoolFactoryImpl in project geode by apache.

the class LocatorTestBase method startBridgeClient.

protected void startBridgeClient(final String group, final String host, final int port, final String[] regions) throws Exception {
    PoolFactoryImpl pf = new PoolFactoryImpl(null);
    pf.addLocator(host, port).setServerGroup(group).setPingInterval(200).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1);
    startBridgeClient(pf.getPoolAttributes(), regions);
}
Also used : PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl)

Example 8 with PoolFactoryImpl

use of org.apache.geode.internal.cache.PoolFactoryImpl in project geode by apache.

the class LocatorTestBase method startBridgeClient.

protected void startBridgeClient(final Pool pool, final String[] regions) throws Exception {
    Properties props = new Properties();
    props.setProperty(MCAST_PORT, String.valueOf(0));
    props.setProperty(LOCATORS, "");
    DistributedSystem ds = getSystem(props);
    Cache cache = CacheFactory.create(ds);
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setPoolName(POOL_NAME);
    PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
    pf.init(pool);
    LocatorDiscoveryCallback locatorCallback = new MyLocatorCallback();
    remoteObjects.put(CALLBACK_KEY, locatorCallback);
    pf.setLocatorDiscoveryCallback(locatorCallback);
    pf.create(POOL_NAME);
    RegionAttributes attrs = factory.create();
    for (int i = 0; i < regions.length; i++) {
        cache.createRegion(regions[i], attrs);
    }
    remoteObjects.put(CACHE_KEY, cache);
}
Also used : AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) Properties(java.util.Properties) DistributedSystem(org.apache.geode.distributed.DistributedSystem) Cache(org.apache.geode.cache.Cache) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl)

Example 9 with PoolFactoryImpl

use of org.apache.geode.internal.cache.PoolFactoryImpl in project geode by apache.

the class CacheXml66DUnitTest method testAlreadyExistingPool.

@Test
public void testAlreadyExistingPool() throws Exception {
    getSystem();
    PoolFactoryImpl f = (PoolFactoryImpl) PoolManager.createFactory();
    f.setStartDisabled(true).addLocator(ALIAS2, 12345).create("mypool");
    try {
        // now make sure declarative cache can't create the same pool
        CacheCreation cache = new CacheCreation();
        cache.createPoolFactory().addLocator(ALIAS2, 12345).create("mypool");
        IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.PoolManagerImpl_POOL_NAMED_0_ALREADY_EXISTS.toLocalizedString("mypool"));
        try {
            testXml(cache);
            fail("expected IllegalStateException");
        } catch (IllegalStateException expected) {
        } finally {
            expectedException.remove();
        }
    } finally {
        PoolManager.close();
    }
}
Also used : IgnoredException(org.apache.geode.test.dunit.IgnoredException) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl) Test(org.junit.Test)

Example 10 with PoolFactoryImpl

use of org.apache.geode.internal.cache.PoolFactoryImpl in project geode by apache.

the class CacheServerTestUtil method createCacheClient.

public static void createCacheClient(Pool poolAttr, String regionName, Properties dsProperties, Boolean addControlListener, Properties javaSystemProperties) throws Exception {
    new CacheServerTestUtil().createCache(dsProperties);
    IgnoredException.addIgnoredException("java.net.ConnectException||java.net.SocketException");
    if (javaSystemProperties != null && javaSystemProperties.size() > 0) {
        Enumeration e = javaSystemProperties.propertyNames();
        while (e.hasMoreElements()) {
            String key = (String) e.nextElement();
            System.setProperty(key, javaSystemProperties.getProperty(key));
        }
    }
    PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
    pf.init(poolAttr);
    PoolImpl p = (PoolImpl) pf.create("CacheServerTestUtil");
    AttributesFactory factory = new AttributesFactory();
    factory.setScope(Scope.LOCAL);
    factory.setPoolName(p.getName());
    if (addControlListener.booleanValue()) {
        factory.addCacheListener(new ControlListener());
    }
    RegionAttributes attrs = factory.create();
    cache.createRegion(regionName, attrs);
    pool = p;
}
Also used : Enumeration(java.util.Enumeration) AttributesFactory(org.apache.geode.cache.AttributesFactory) RegionAttributes(org.apache.geode.cache.RegionAttributes) PoolImpl(org.apache.geode.cache.client.internal.PoolImpl) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl)

Aggregations

PoolFactoryImpl (org.apache.geode.internal.cache.PoolFactoryImpl)27 PoolFactory (org.apache.geode.cache.client.PoolFactory)10 Test (org.junit.Test)9 AttributesFactory (org.apache.geode.cache.AttributesFactory)7 ClientServerTest (org.apache.geode.test.junit.categories.ClientServerTest)7 Pool (org.apache.geode.cache.client.Pool)6 RegionAttributes (org.apache.geode.cache.RegionAttributes)5 PoolImpl (org.apache.geode.cache.client.internal.PoolImpl)5 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)5 Host (org.apache.geode.test.dunit.Host)4 VM (org.apache.geode.test.dunit.VM)4 ServerLocation (org.apache.geode.distributed.internal.ServerLocation)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Properties (java.util.Properties)2 DiskStore (org.apache.geode.cache.DiskStore)2 ServerLoad (org.apache.geode.cache.server.ServerLoad)2 IgnoredException (org.apache.geode.test.dunit.IgnoredException)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2