use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class DurableClientReconnectDUnitTest method getPoolFactory.
private PoolFactory getPoolFactory() {
Host host = Host.getHost(0);
PoolFactory factory = PoolManager.createFactory().addServer(NetworkUtils.getServerHostName(host), PORT1.intValue()).addServer(NetworkUtils.getServerHostName(host), PORT2.intValue()).addServer(NetworkUtils.getServerHostName(host), PORT3.intValue()).addServer(NetworkUtils.getServerHostName(host), PORT4.intValue());
return factory;
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class PdxClientServerDUnitTest method testMultipleServerDSes.
/**
* Test to make sure that types are sent to all pools, even if they are in multiple distributed
* systems.
*/
@Test
public void testMultipleServerDSes() throws Exception {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
final int port1 = createLonerServerRegion(vm0, "region1", "1");
final int port2 = createLonerServerRegion(vm1, "region2", "2");
SerializableCallable createRegion = new SerializableCallable() {
public Object call() throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
getSystem(props);
Cache cache = getCache();
PoolFactory pf = PoolManager.createFactory();
pf.addServer(NetworkUtils.getServerHostName(vm0.getHost()), port1);
pf.create("pool1");
pf = PoolManager.createFactory();
pf.addServer(NetworkUtils.getServerHostName(vm0.getHost()), port2);
pf.create("pool2");
AttributesFactory af = new AttributesFactory();
af.setPoolName("pool1");
cache.createRegion("region1", af.create());
af = new AttributesFactory();
af.setPoolName("pool2");
cache.createRegion("region2", af.create());
return null;
}
};
vm2.invoke(createRegion);
vm3.invoke(createRegion);
createRegion.call();
// Serialize an object and put it in both regions, sending
// the event to each pool
vm2.invoke(() -> {
HeapDataOutputStream bytes = new HeapDataOutputStream(Version.CURRENT);
Region r1 = getRootRegion("region1");
r1.put(1, new SimpleClass(57, (byte) 3));
Region r2 = getRootRegion("region2");
r2.put(1, new SimpleClass(57, (byte) 3));
return null;
});
// Make sure we get deserialize the value in a different client
vm3.invoke(() -> {
Region r = getRootRegion("region1");
assertEquals(new SimpleClass(57, (byte) 3), r.get(1));
return null;
});
// Make sure we can get the entry in the current member
Region r = getRootRegion("region2");
assertEquals(new SimpleClass(57, (byte) 3), r.get(1));
}
use of org.apache.geode.cache.client.PoolFactory in project geode by apache.
the class PdxClientServerDUnitTest method testLatePoolCreation.
/**
* Test that we still use the client type registry, even if pool is created late.
*/
@Test
public void testLatePoolCreation() {
Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
final int port = vm0.invoke(() -> createServerRegion(SimpleClass.class));
SerializableCallable createRegion = new SerializableCallable() {
public Object call() throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
getSystem(props);
Cache cache = getCache();
PoolFactory pf = PoolManager.createFactory();
pf.addServer(NetworkUtils.getServerHostName(vm0.getHost()), port);
pf.create("pool");
AttributesFactory af = new AttributesFactory();
af.setPoolName("pool");
cache.createRegion("testSimplePdx", af.create());
return null;
}
};
vm1.invoke(createRegion);
vm2.invoke(createRegion);
vm1.invoke(() -> {
Region r = getRootRegion("testSimplePdx");
r.put(1, new SimpleClass(57, (byte) 3));
return null;
});
final SerializableCallable checkValue = new SerializableCallable() {
public Object call() throws Exception {
Region r = getRootRegion("testSimplePdx");
assertEquals(new SimpleClass(57, (byte) 3), r.get(1));
return null;
}
};
vm2.invoke(checkValue);
vm0.invoke(checkValue);
}
use of org.apache.geode.cache.client.PoolFactory 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.PoolFactory 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);
}
}
Aggregations