Search in sources :

Example 1 with PoolFactoryImpl

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

the class LocatorLoadBalancingDUnitTest method testCustomLoadProbe.

@Test
public void testCustomLoadProbe() 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);
    final ServerLoad load1 = new ServerLoad(.3f, .01f, .44f, 4564f);
    final ServerLoad load2 = new ServerLoad(23.2f, 1.1f, 22.3f, .3f);
    int serverPort1 = vm1.invoke("Start BridgeServer", () -> startBridgeServer(null, locators, new String[] { REGION_NAME }, new MyLoadProbe(load1), false));
    int serverPort2 = vm2.invoke("Start BridgeServer", () -> startBridgeServer(null, locators, new String[] { REGION_NAME }, new MyLoadProbe(load2), false));
    HashMap expected = new HashMap();
    ServerLocation l1 = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort1);
    ServerLocation l2 = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort2);
    expected.put(l1, load1);
    expected.put(l2, load2);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    load1.setConnectionLoad(25f);
    vm1.invoke("changeLoad", () -> changeLoad(load1));
    load2.setSubscriptionConnectionLoad(3.5f);
    vm2.invoke("changeLoad", () -> changeLoad(load2));
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    final ServerLoad load1Updated = new ServerLoad(1f, .1f, 0f, 1f);
    final ServerLoad load2Updated = new ServerLoad(2f, 5f, 0f, 2f);
    expected.put(l1, load1Updated);
    expected.put(l2, load2Updated);
    vm1.invoke("changeLoad", () -> changeLoad(load1Updated));
    vm2.invoke("changeLoad", () -> changeLoad(load2Updated));
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    PoolFactoryImpl pf = new PoolFactoryImpl(null);
    pf.addLocator(NetworkUtils.getServerHostName(host), locatorPort);
    pf.setMinConnections(20);
    pf.setSubscriptionEnabled(true);
    pf.setIdleTimeout(-1);
    startBridgeClient(pf.getPoolAttributes(), new String[] { REGION_NAME });
    waitForPrefilledConnections(20);
    // The first 10 connection should to go vm1, then 1 to vm2, then another 9 to vm1
    // because have unequal values for loadPerConnection
    vm1.invoke("Check Connection Count", () -> checkConnectionCount(19));
    vm2.invoke("Check Connection Count", () -> checkConnectionCount(1));
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) HashMap(java.util.HashMap) 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 2 with PoolFactoryImpl

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

the class LocatorLoadBalancingDUnitTest method testBalancing.

/**
   * Test to make sure that the locator balancing load between two servers.
   *
   * @throws Exception
   */
@Test
public void testBalancing() 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);
    vm1.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "a", "b" }, locators));
    vm2.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "a", "b" }, locators));
    vm3.invoke("StartBridgeClient", () -> {
        PoolFactoryImpl pf = new PoolFactoryImpl(null);
        pf.addLocator(NetworkUtils.getServerHostName(host), locatorPort);
        pf.setMinConnections(80);
        pf.setMaxConnections(80);
        pf.setSubscriptionEnabled(false);
        pf.setIdleTimeout(-1);
        startBridgeClient(pf.getPoolAttributes(), new String[] { REGION_NAME });
        return null;
    });
    vm3.invoke("waitForPrefilledConnections", () -> waitForPrefilledConnections(80));
    vm1.invoke("check connection count", () -> checkConnectionCount(40));
    vm2.invoke("check connection count", () -> checkConnectionCount(40));
}
Also used : 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 3 with PoolFactoryImpl

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

the class PoolManagerJUnitTest method testRegionFind.

@Test
public void testRegionFind() {
    PoolFactory cpf = PoolManager.createFactory();
    ((PoolFactoryImpl) cpf).setStartDisabled(true);
    Pool pool = cpf.addLocator("localhost", 12345).create("mypool");
    Cache cache = CacheFactory.create(ds);
    AttributesFactory fact = new AttributesFactory();
    fact.setPoolName(pool.getName());
    Region region = cache.createRegion("myRegion", fact.create());
    assertEquals(pool, PoolManager.find(region));
}
Also used : PoolFactory(org.apache.geode.cache.client.PoolFactory) Pool(org.apache.geode.cache.client.Pool) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl) ClientServerTest(org.apache.geode.test.junit.categories.ClientServerTest) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 4 with PoolFactoryImpl

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

the class CacheCreation method create.

/**
   * Fills in the contents of a {@link Cache} based on this creation object's state.
   */
void create(InternalCache cache) throws TimeoutException, CacheWriterException, GatewayException, RegionExistsException {
    this.extensionPoint.beforeCreate(cache);
    cache.setDeclarativeCacheConfig(this.cacheConfig);
    if (cache.isClient()) {
        throw new IllegalStateException("You must use client-cache in the cache.xml when ClientCacheFactory is used.");
    }
    if (this.hasLockLease()) {
        cache.setLockLease(this.lockLease);
    }
    if (this.hasLockTimeout()) {
        cache.setLockTimeout(this.lockTimeout);
    }
    if (this.hasSearchTimeout()) {
        cache.setSearchTimeout(this.searchTimeout);
    }
    if (this.hasMessageSyncInterval()) {
        cache.setMessageSyncInterval(this.getMessageSyncInterval());
    }
    if (this.gatewayConflictResolver != null) {
        cache.setGatewayConflictResolver(this.gatewayConflictResolver);
    }
    // create connection pools
    Map<String, Pool> pools = getPools();
    if (!pools.isEmpty()) {
        for (Pool pool : pools.values()) {
            PoolFactoryImpl poolFactory = (PoolFactoryImpl) PoolManager.createFactory();
            poolFactory.init(pool);
            poolFactory.create(pool.getName());
        }
    }
    if (hasResourceManager()) {
        // moved this up to fix bug 42128
        getResourceManager().configure(cache.getResourceManager());
    }
    DiskStoreAttributesCreation pdxRegDSC = initializePdxDiskStore(cache);
    cache.initializePdxRegistry();
    for (DiskStore diskStore : this.diskStores.values()) {
        DiskStoreAttributesCreation creation = (DiskStoreAttributesCreation) diskStore;
        if (creation != pdxRegDSC) {
            createDiskStore(creation, cache);
        }
    }
    if (this.hasDynamicRegionFactory()) {
        DynamicRegionFactory.get().open(this.getDynamicRegionFactoryConfig());
    }
    if (this.hasServer()) {
        cache.setIsServer(this.isServer);
    }
    if (this.hasCopyOnRead()) {
        cache.setCopyOnRead(this.copyOnRead);
    }
    if (this.txMgrCreation != null && this.txMgrCreation.getListeners().length > 0 && cache.getCacheTransactionManager() != null) {
        cache.getCacheTransactionManager().initListeners(this.txMgrCreation.getListeners());
    }
    if (this.txMgrCreation != null && cache.getCacheTransactionManager() != null) {
        cache.getCacheTransactionManager().setWriter(this.txMgrCreation.getWriter());
    }
    for (GatewaySender senderCreation : this.getGatewaySenders()) {
        GatewaySenderFactory factory = cache.createGatewaySenderFactory();
        ((InternalGatewaySenderFactory) factory).configureGatewaySender(senderCreation);
        GatewaySender gatewaySender = factory.create(senderCreation.getId(), senderCreation.getRemoteDSId());
        // Start the sender if it is not set to manually start
        if (gatewaySender.isManualStart()) {
            cache.getLoggerI18n().info(LocalizedStrings.CacheCreation_0_IS_NOT_BEING_STARTED_SINCE_IT_IS_CONFIGURED_FOR_MANUAL_START, gatewaySender);
        }
    }
    for (AsyncEventQueue asyncEventQueueCreation : this.getAsyncEventQueues()) {
        AsyncEventQueueFactoryImpl asyncQueueFactory = (AsyncEventQueueFactoryImpl) cache.createAsyncEventQueueFactory();
        asyncQueueFactory.configureAsyncEventQueue(asyncEventQueueCreation);
        AsyncEventQueue asyncEventQueue = cache.getAsyncEventQueue(asyncEventQueueCreation.getId());
        if (asyncEventQueue == null) {
            asyncQueueFactory.create(asyncEventQueueCreation.getId(), asyncEventQueueCreation.getAsyncEventListener());
        }
    }
    cache.initializePdxRegistry();
    for (String id : this.regionAttributesNames) {
        RegionAttributesCreation creation = (RegionAttributesCreation) getRegionAttributes(id);
        creation.inheritAttributes(cache, false);
        // Don't let the RegionAttributesCreation escape to the user
        AttributesFactory<?, ?> factory = new AttributesFactory<>(creation);
        RegionAttributes<?, ?> attrs = factory.create();
        cache.setRegionAttributes(id, attrs);
    }
    initializeRegions(this.roots, cache);
    cache.readyDynamicRegionFactory();
    // Create and start the BridgeServers. This code was moved from
    // before region initialization to after it to fix bug 33587.
    // Create and start the CacheServers after the gateways have been initialized
    // to fix bug 39736.
    Integer serverPort = CacheServerLauncher.getServerPort();
    String serverBindAdd = CacheServerLauncher.getServerBindAddress();
    Boolean disableDefaultServer = CacheServerLauncher.getDisableDefaultServer();
    startCacheServers(getCacheServers(), cache, serverPort, serverBindAdd, disableDefaultServer);
    for (GatewayReceiver receiverCreation : this.getGatewayReceivers()) {
        GatewayReceiverFactory factory = cache.createGatewayReceiverFactory();
        factory.setBindAddress(receiverCreation.getBindAddress());
        factory.setMaximumTimeBetweenPings(receiverCreation.getMaximumTimeBetweenPings());
        factory.setStartPort(receiverCreation.getStartPort());
        factory.setEndPort(receiverCreation.getEndPort());
        factory.setSocketBufferSize(receiverCreation.getSocketBufferSize());
        factory.setManualStart(receiverCreation.isManualStart());
        for (GatewayTransportFilter filter : receiverCreation.getGatewayTransportFilters()) {
            factory.addGatewayTransportFilter(filter);
        }
        factory.setHostnameForSenders(receiverCreation.getHost());
        GatewayReceiver receiver = factory.create();
        if (receiver.isManualStart()) {
            cache.getLoggerI18n().info(LocalizedStrings.CacheCreation_0_IS_NOT_BEING_STARTED_SINCE_IT_IS_CONFIGURED_FOR_MANUAL_START, receiver);
        }
    }
    cache.setBackupFiles(this.backups);
    cache.addDeclarableProperties(this.declarablePropertiesMap);
    runInitializer();
    cache.setInitializer(getInitializer(), getInitializerProps());
    // Create all extensions
    this.extensionPoint.fireCreate(cache);
}
Also used : AbstractGatewaySender(org.apache.geode.internal.cache.wan.AbstractGatewaySender) GatewaySender(org.apache.geode.cache.wan.GatewaySender) GatewayReceiverFactory(org.apache.geode.cache.wan.GatewayReceiverFactory) GatewayReceiver(org.apache.geode.cache.wan.GatewayReceiver) PoolFactoryImpl(org.apache.geode.internal.cache.PoolFactoryImpl) DiskStore(org.apache.geode.cache.DiskStore) AttributesFactory(org.apache.geode.cache.AttributesFactory) AsyncEventQueueFactoryImpl(org.apache.geode.cache.asyncqueue.internal.AsyncEventQueueFactoryImpl) InternalGatewaySenderFactory(org.apache.geode.internal.cache.wan.InternalGatewaySenderFactory) GatewaySenderFactory(org.apache.geode.cache.wan.GatewaySenderFactory) AsyncEventQueue(org.apache.geode.cache.asyncqueue.AsyncEventQueue) Pool(org.apache.geode.cache.client.Pool) GatewayTransportFilter(org.apache.geode.cache.wan.GatewayTransportFilter) InternalGatewaySenderFactory(org.apache.geode.internal.cache.wan.InternalGatewaySenderFactory)

Example 5 with PoolFactoryImpl

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

the class LocatorLoadBalancingDUnitTest method testLoadMessaging.

/**
   * Test to make sure the bridge servers communicate their updated load to the controller when the
   * load on the bridge server changes.
   *
   * @throws Exception
   */
@Test
public void testLoadMessaging() throws Exception {
    final Host host = Host.getHost(0);
    VM vm0 = host.getVM(0);
    VM vm1 = host.getVM(1);
    VM vm2 = host.getVM(2);
    int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
    String hostName = NetworkUtils.getServerHostName(vm0.getHost());
    vm0.invoke("Start Locator", () -> startLocator(hostName, locatorPort, ""));
    String locators = getLocatorString(host, locatorPort);
    final int serverPort = vm1.invoke("Start BridgeServer", () -> startBridgeServer(new String[] { "a", "b" }, locators));
    // We expect 0 load
    Map expected = new HashMap();
    ServerLocation expectedLocation = new ServerLocation(NetworkUtils.getServerHostName(host), serverPort);
    ServerLoad expectedLoad = new ServerLoad(0f, 1 / 800.0f, 0f, 1f);
    expected.put(expectedLocation, expectedLoad);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    vm2.invoke("StartBridgeClient", () -> {
        PoolFactoryImpl pf = new PoolFactoryImpl(null);
        pf.addServer(NetworkUtils.getServerHostName(host), serverPort);
        pf.setMinConnections(8);
        pf.setMaxConnections(8);
        pf.setSubscriptionEnabled(true);
        startBridgeClient(pf.getPoolAttributes(), new String[] { REGION_NAME });
        return null;
    });
    // We expect 8 client to server connections. The queue requires
    // an additional client to server connection, but that shouldn't show up here.
    expectedLoad = new ServerLoad(8 / 800f, 1 / 800.0f, 1f, 1f);
    expected.put(expectedLocation, expectedLoad);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
    stopBridgeMemberVM(vm2);
    // Now we expect 0 load
    expectedLoad = new ServerLoad(0f, 1 / 800.0f, 0f, 1f);
    expected.put(expectedLocation, expectedLoad);
    vm0.invoke("check Locator Load", () -> checkLocatorLoad(expected));
}
Also used : ServerLoad(org.apache.geode.cache.server.ServerLoad) HashMap(java.util.HashMap) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) VM(org.apache.geode.test.dunit.VM) Host(org.apache.geode.test.dunit.Host) HashMap(java.util.HashMap) Map(java.util.Map) 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)

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