use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DurableClientReconnectDUnitTest method createCacheClientAndConnectToSingleServerWithZeroConnPerServer.
private void createCacheClientAndConnectToSingleServerWithZeroConnPerServer(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).setMinConnections(0).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);
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class ReliableMessagingDUnitTest method createClientCache.
public static void createClientCache(int port1, int port2) throws Exception {
ReliableMessagingDUnitTest test = new ReliableMessagingDUnitTest();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
cache = test.createCache(props);
String host = NetworkUtils.getServerHostName(Host.getHost(0));
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host, PORT1).addServer(host, PORT2).setSubscriptionEnabled(true).setSubscriptionRedundancy(1).setThreadLocalConnections(true).setMinConnections(6).setReadTimeout(20000).setPingInterval(10000).setRetryAttempts(5).setSubscriptionAckInterval(CLIENT_ACK_INTERVAL).create("ReliableMessagingDUnitTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setPoolName(p.getName());
RegionAttributes attrs = factory.create();
Region region = cache.createRegion(REGION_NAME, attrs);
region.registerInterest("ALL_KEYS");
pool = p;
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class SecurityTestUtils method createCacheClientForMultiUserMode.
protected static void createCacheClientForMultiUserMode(final int numOfUsers, final String authInitModule, final Properties[] authProps, final Properties javaProps, final int[] ports, final int numConnections, final boolean setupDynamicRegionFactory, final String durableClientId, final int expectedResult) {
if (numOfUsers < 1) {
fail("Number of users cannot be less than one");
}
multiUserAuthMode = true;
if (numOfUsers != authProps.length) {
fail("Number of authProps provided does not match with numOfUsers specified, " + authProps.length);
}
if (authProps[0] == null) {
authProps[0] = new Properties();
}
authProps[0].setProperty(MCAST_PORT, "0");
authProps[0].setProperty(LOCATORS, "");
authProps[0].setProperty(SECURITY_LOG_LEVEL, "finest");
Properties props = new Properties();
if (authInitModule != null) {
authProps[0].setProperty(SECURITY_CLIENT_AUTH_INIT, authInitModule);
props.setProperty(SECURITY_CLIENT_AUTH_INIT, authInitModule);
}
if (durableClientId != null) {
props.setProperty(DURABLE_CLIENT_ID, durableClientId);
props.setProperty(DURABLE_CLIENT_TIMEOUT, String.valueOf(DistributionConfig.DEFAULT_DURABLE_CLIENT_TIMEOUT));
}
SecurityTestUtils tmpInstance = new SecurityTestUtils("temp");
tmpInstance.createSystem(props, javaProps);
AttributesFactory factory = new AttributesFactory();
int[] portsI = new int[ports.length];
for (int z = 0; z < ports.length; z++) {
portsI[z] = ports[z];
}
try {
tmpInstance.openCache();
PoolFactory poolFactory = PoolManager.createFactory();
poolFactory.setRetryAttempts(200);
poolFactory.setMultiuserAuthentication(multiUserAuthMode);
poolFactory.setSubscriptionEnabled(true);
pool = configureConnectionPoolWithNameAndFactory(factory, getIPLiteral(), portsI, true, 1, numConnections, null, null, poolFactory);
if (setupDynamicRegionFactory) {
initClientDynamicRegionFactory(pool.getName());
}
proxyCaches = new ProxyCache[numOfUsers];
for (int i = 0; i < numOfUsers; i++) {
proxyCaches[i] = (ProxyCache) ((PoolImpl) pool).createAuthenticatedCacheView(authProps[i]);
}
factory.setScope(Scope.LOCAL);
factory.setDataPolicy(DataPolicy.EMPTY);
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
if (expectedResult != NO_EXCEPTION && expectedResult != NOFORCE_AUTHREQ_EXCEPTION) {
if (!multiUserAuthMode) {
fail("Expected an exception when starting client");
}
}
} catch (AuthenticationRequiredException ex) {
if (expectedResult == AUTHREQ_EXCEPTION || expectedResult == NOFORCE_AUTHREQ_EXCEPTION) {
getLogWriter().info("Got expected exception when starting client: " + ex);
} else {
fail("Got unexpected exception when starting client", ex);
}
} catch (AuthenticationFailedException ex) {
if (expectedResult == AUTHFAIL_EXCEPTION) {
getLogWriter().info("Got expected exception when starting client: " + ex);
} else {
fail("Got unexpected exception when starting client", ex);
}
} catch (ServerRefusedConnectionException ex) {
if (expectedResult == CONNREFUSED_EXCEPTION) {
getLogWriter().info("Got expected exception when starting client: " + ex);
} else {
fail("Got unexpected exception when starting client", ex);
}
} catch (Exception ex) {
fail("Got unexpected exception when starting client", ex);
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class SecurityTestUtils method createCacheClient.
// 5
protected static void createCacheClient(final String authInitModule, Properties authProps, final Properties javaProps, int[] ports, final int numConnections, final boolean setupDynamicRegionFactory, final boolean multiUserMode, final boolean subscriptionEnabled, final int expectedResult) {
multiUserAuthMode = multiUserMode;
if (authProps == null) {
authProps = new Properties();
}
authProps.setProperty(MCAST_PORT, "0");
authProps.setProperty(LOCATORS, "");
authProps.setProperty(SECURITY_LOG_LEVEL, "finest");
// TODO (ashetkar) Add " && (!multiUserAuthMode)" below.
if (authInitModule != null) {
authProps.setProperty(SECURITY_CLIENT_AUTH_INIT, authInitModule);
}
SecurityTestUtils tmpInstance = new SecurityTestUtils("temp");
tmpInstance.createSystem(authProps, javaProps);
AttributesFactory factory = new AttributesFactory();
int[] portsI = new int[ports.length];
for (int z = 0; z < ports.length; z++) {
portsI[z] = ports[z];
}
try {
PoolFactory poolFactory = PoolManager.createFactory();
poolFactory.setRetryAttempts(200);
if (multiUserAuthMode) {
poolFactory.setMultiuserAuthentication(multiUserAuthMode);
// [sumedh] Why is this false here only to be overridden in
// ClientServerTestCase.configureConnectionPoolWithNameAndFactory below?
// Actually setting it to false causes MultiUserAPIDUnitTest to fail.
// poolFactory.setSubscriptionEnabled(false);
}
pool = configureConnectionPoolWithNameAndFactory(factory, getIPLiteral(), portsI, subscriptionEnabled, 0, numConnections, null, null, poolFactory);
if (setupDynamicRegionFactory) {
initClientDynamicRegionFactory(pool.getName());
}
tmpInstance.openCache();
try {
getLogWriter().info("multi-user mode " + multiUserAuthMode);
proxyCaches[0] = (ProxyCache) ((PoolImpl) pool).createAuthenticatedCacheView(authProps);
if (!multiUserAuthMode) {
fail("Expected a UnsupportedOperationException but got none in single-user mode");
}
} catch (UnsupportedOperationException uoe) {
if (!multiUserAuthMode) {
getLogWriter().info("Got expected UnsupportedOperationException in single-user mode");
} else {
fail("Got unexpected exception in multi-user mode ", uoe);
}
}
factory.setScope(Scope.LOCAL);
if (multiUserAuthMode) {
factory.setDataPolicy(DataPolicy.EMPTY);
}
RegionAttributes attrs = factory.create();
cache.createRegionFactory(attrs).create(REGION_NAME);
// if (expectedResult != NO_EXCEPTION && expectedResult != NOFORCE_AUTHREQ_EXCEPTION) {
// if (!multiUserAuthMode) {
// fail("Expected an exception when starting client");
// }
// }
} catch (AuthenticationRequiredException ex) {
if (expectedResult == AUTHREQ_EXCEPTION || expectedResult == NOFORCE_AUTHREQ_EXCEPTION) {
getLogWriter().info("Got expected exception when starting client: " + ex);
} else {
fail("Got unexpected exception when starting client", ex);
}
} catch (AuthenticationFailedException ex) {
if (expectedResult == AUTHFAIL_EXCEPTION) {
getLogWriter().info("Got expected exception when starting client: " + ex);
} else {
fail("Got unexpected exception when starting client", ex);
}
} catch (ServerRefusedConnectionException ex) {
if (expectedResult == CONNREFUSED_EXCEPTION) {
getLogWriter().info("Got expected exception when starting client: " + ex);
} else {
fail("Got unexpected exception when starting client", ex);
}
} catch (GemFireSecurityException ex) {
if (expectedResult == SECURITY_EXCEPTION) {
getLogWriter().info("Got expected exception when starting client: " + ex);
} else {
fail("Got unexpected exception when starting client", ex);
}
} catch (Exception ex) {
fail("Got unexpected exception when starting client", ex);
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class ClientRegisterInterestDUnitTest method testRegisterInterestFailover.
/**
* Tests failover of register interest from client point of view. Related bugs include:
*
* <p>
* Bug 35654 "failed re-registration may never be detected and thus may never re-re-register"
*
* <p>
* Bug 35639 "registerInterest re-registration happens everytime a healthy server is detected"
*
* <p>
* Bug 35655 "a single failed re-registration causes all other pending re-registrations to be
* cancelled"
*/
@Ignore("TODO")
@Test
public void testRegisterInterestFailover() throws Exception {
// controller is bridge client
final Host host = Host.getHost(0);
final String name = this.getUniqueName();
final String regionName1 = name + "-1";
final String regionName2 = name + "-2";
final String regionName3 = name + "-3";
final String key1 = "KEY-" + regionName1 + "-1";
final String key2 = "KEY-" + regionName1 + "-2";
final String key3 = "KEY-" + regionName1 + "-3";
// 3 servers in this test
final int[] ports = new int[3];
// create first bridge server with region for client...
final int firstServerIdx = 0;
final VM firstServerVM = Host.getHost(0).getVM(firstServerIdx);
firstServerVM.invoke(new CacheSerializableRunnable("Create first bridge server") {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] Create first bridge server");
getSystem();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
Region region1 = createRootRegion(regionName1, factory.create());
Region region2 = createRootRegion(regionName2, factory.create());
Region region3 = createRootRegion(regionName3, factory.create());
region1.put(key1, "VAL-1");
region2.put(key2, "VAL-1");
region3.put(key3, "VAL-1");
try {
bridgeServerPort = startBridgeServer(0);
} catch (IOException e) {
LogWriterUtils.getLogWriter().error("startBridgeServer threw IOException", e);
fail("startBridgeServer threw IOException ", e);
}
assertTrue(bridgeServerPort != 0);
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] " + "firstServer port=" + bridgeServerPort);
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] " + "firstServer memberId=" + getMemberId());
}
});
// create second bridge server missing region for client...
final int secondServerIdx = 1;
final VM secondServerVM = Host.getHost(0).getVM(secondServerIdx);
secondServerVM.invoke(new CacheSerializableRunnable("Create second bridge server") {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] Create second bridge server");
getSystem();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
Region region1 = createRootRegion(regionName1, factory.create());
Region region3 = createRootRegion(regionName3, factory.create());
region1.put(key1, "VAL-2");
region3.put(key3, "VAL-2");
try {
bridgeServerPort = startBridgeServer(0);
} catch (IOException e) {
LogWriterUtils.getLogWriter().error("startBridgeServer threw IOException", e);
fail("startBridgeServer threw IOException ", e);
}
assertTrue(bridgeServerPort != 0);
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] " + "secondServer port=" + bridgeServerPort);
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] " + "secondServer memberId=" + getMemberId());
}
});
// get the bridge server ports...
ports[firstServerIdx] = firstServerVM.invoke(() -> ClientRegisterInterestDUnitTest.getBridgeServerPort());
assertTrue(ports[firstServerIdx] != 0);
ports[secondServerIdx] = secondServerVM.invoke(() -> ClientRegisterInterestDUnitTest.getBridgeServerPort());
assertTrue(ports[secondServerIdx] != 0);
assertTrue(ports[firstServerIdx] != ports[secondServerIdx]);
// stop second and third servers
secondServerVM.invoke(new CacheSerializableRunnable("Stop second bridge server") {
public void run2() throws CacheException {
stopBridgeServers(getCache());
}
});
// create the bridge client
LogWriterUtils.getLogWriter().info("[testBug35654] create bridge client");
Properties config = new Properties();
config.setProperty(MCAST_PORT, "0");
config.setProperty(LOCATORS, "");
getSystem(config);
getCache();
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
LogWriterUtils.getLogWriter().info("[testRegisterInterestFailover] creating connection pool");
boolean establishCallbackConnection = true;
final PoolImpl p = (PoolImpl) ClientServerTestCase.configureConnectionPool(factory, NetworkUtils.getServerHostName(host), ports, establishCallbackConnection, -1, -1, null);
final Region region1 = createRootRegion(regionName1, factory.create());
final Region region2 = createRootRegion(regionName2, factory.create());
final Region region3 = createRootRegion(regionName3, factory.create());
assertTrue(region1.getInterestList().isEmpty());
assertTrue(region2.getInterestList().isEmpty());
assertTrue(region3.getInterestList().isEmpty());
region1.registerInterest(key1);
region2.registerInterest(key2);
region3.registerInterest(key3);
assertTrue(region1.getInterestList().contains(key1));
assertTrue(region2.getInterestList().contains(key2));
assertTrue(region3.getInterestList().contains(key3));
assertTrue(region1.getInterestListRegex().isEmpty());
assertTrue(region2.getInterestListRegex().isEmpty());
assertTrue(region3.getInterestListRegex().isEmpty());
// get ConnectionProxy and wait until connected to first server
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return p.getPrimaryPort() != -1;
}
public String description() {
return "primary port remained invalid";
}
};
Wait.waitForCriterion(ev, 10 * 1000, 200, true);
assertEquals(ports[firstServerIdx], p.getPrimaryPort());
// assert intial values
assertEquals("VAL-1", region1.get(key1));
assertEquals("VAL-1", region2.get(key2));
assertEquals("VAL-1", region3.get(key3));
// do puts on server1 and make sure values come thru for all 3 registrations
firstServerVM.invoke(new CacheSerializableRunnable("Puts from first bridge server") {
public void run2() throws CacheException {
Region region1 = getCache().getRegion(regionName1);
region1.put(key1, "VAL-1-1");
Region region2 = getCache().getRegion(regionName2);
region2.put(key2, "VAL-1-1");
Region region3 = getCache().getRegion(regionName3);
region3.put(key3, "VAL-1-1");
}
});
ev = new WaitCriterion() {
public boolean done() {
if (!"VAL-1-1".equals(region1.get(key1)) || !"VAL-1-1".equals(region2.get(key2)) || !"VAL-1-1".equals(region3.get(key3)))
return false;
return true;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 10 * 1000, 200, true);
assertEquals("VAL-1-1", region1.get(key1));
assertEquals("VAL-1-1", region2.get(key2));
assertEquals("VAL-1-1", region3.get(key3));
// force failover to server 2
secondServerVM.invoke(new CacheSerializableRunnable("Start second bridge server") {
public void run2() throws CacheException {
try {
startBridgeServer(ports[secondServerIdx]);
} catch (IOException e) {
LogWriterUtils.getLogWriter().error("startBridgeServer threw IOException", e);
fail("startBridgeServer threw IOException ", e);
}
}
});
firstServerVM.invoke(new CacheSerializableRunnable("Stop first bridge server") {
public void run2() throws CacheException {
stopBridgeServers(getCache());
}
});
// wait for failover to second server
ev = new WaitCriterion() {
public boolean done() {
return ports[secondServerIdx] == p.getPrimaryPort();
}
public String description() {
return "primary port never became " + ports[secondServerIdx];
}
};
Wait.waitForCriterion(ev, 100 * 1000, 200, true);
try {
assertEquals(null, region2.get(key2));
fail("CacheLoaderException expected");
} catch (CacheLoaderException e) {
}
// region2 registration should be gone now
// do puts on server2 and make sure values come thru for only 2 registrations
secondServerVM.invoke(new CacheSerializableRunnable("Puts from second bridge server") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
createRootRegion(regionName2, factory.create());
}
});
// assert that there is no actively registered interest on region2
assertTrue(region2.getInterestList().isEmpty());
assertTrue(region2.getInterestListRegex().isEmpty());
region2.put(key2, "VAL-0");
secondServerVM.invoke(new CacheSerializableRunnable("Put from second bridge server") {
public void run2() throws CacheException {
Region region1 = getCache().getRegion(regionName1);
region1.put(key1, "VAL-2-2");
Region region2 = getCache().getRegion(regionName2);
region2.put(key2, "VAL-2-1");
Region region3 = getCache().getRegion(regionName3);
region3.put(key3, "VAL-2-2");
}
});
// wait for updates to come thru
ev = new WaitCriterion() {
public boolean done() {
if (!"VAL-2-2".equals(region1.get(key1)) || !"VAL-2-2".equals(region3.get(key3)))
return false;
return true;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 100 * 1000, 200, true);
assertEquals("VAL-2-2", region1.get(key1));
assertEquals("VAL-0", region2.get(key2));
assertEquals("VAL-2-2", region3.get(key3));
// assert again that there is no actively registered interest on region2
assertTrue(region2.getInterestList().isEmpty());
// register interest again on region2 and make
region2.registerInterest(key2);
assertEquals("VAL-2-1", region2.get(key2));
secondServerVM.invoke(new CacheSerializableRunnable("Put from second bridge server") {
public void run2() throws CacheException {
Region region1 = getCache().getRegion(regionName1);
region1.put(key1, "VAL-2-3");
Region region2 = getCache().getRegion(regionName2);
region2.put(key2, "VAL-2-2");
Region region3 = getCache().getRegion(regionName3);
region3.put(key3, "VAL-2-3");
}
});
// wait for updates to come thru
ev = new WaitCriterion() {
public boolean done() {
if (!"VAL-2-3".equals(region1.get(key1)) || !"VAL-2-2".equals(region2.get(key2)) || !"VAL-2-3".equals(region3.get(key3)))
return false;
return true;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 100 * 1000, 200, true);
assertEquals("VAL-2-3", region1.get(key1));
assertEquals("VAL-2-2", region2.get(key2));
assertEquals("VAL-2-3", region3.get(key3));
// assert public methods report actively registered interest on region2
assertTrue(region2.getInterestList().contains(key2));
}
Aggregations