use of org.apache.geode.cache.client.internal.ProxyCache in project geode by apache.
the class CQClientAuthDUnitTest method testPostProcess.
@Test
public void testPostProcess() {
String query = "select * from /" + REGION_NAME;
client1.invoke(() -> {
Properties props = new Properties();
props.setProperty(LOCATORS, "");
props.setProperty(MCAST_PORT, "0");
props.setProperty(SECURITY_CLIENT_AUTH_INIT, UserPasswordAuthInit.class.getName() + ".create");
ClientCacheFactory factory = new ClientCacheFactory(props);
factory.addPoolServer("localhost", server.getPort());
factory.setPoolThreadLocalConnections(false);
factory.setPoolMinConnections(5);
factory.setPoolSubscriptionEnabled(true);
factory.setPoolMultiuserAuthentication(true);
ClientCache clientCache = factory.create();
Region region = clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
Pool pool = PoolManager.find(region);
Properties userProps = new Properties();
userProps.setProperty("security-username", "super-user");
userProps.setProperty("security-password", "1234567");
ProxyCache cache = (ProxyCache) clientCache.createAuthenticatedView(userProps, pool.getName());
QueryService qs = cache.getQueryService();
CqAttributesFactory cqAttributesFactory = new CqAttributesFactory();
CqAttributes cqa = cqAttributesFactory.create();
// Create the CqQuery
CqQuery cq = qs.newCq("CQ1", query, cqa, true);
cq.execute();
});
}
use of org.apache.geode.cache.client.internal.ProxyCache in project geode by apache.
the class FunctionServiceManager method onRegion.
/**
* Returns an {@link Execution} object that can be used to execute a data dependent function on
* the specified Region.<br>
* When invoked from a GemFire client, the method returns an Execution instance that sends a
* message to one of the connected servers as specified by the {@link Pool} for the region. <br>
* Depending on the filters setup on the {@link Execution}, the function is executed on all
* GemFire members that define the data region, or a subset of members.
* {@link Execution#withFilter(Set)}).
*
* For DistributedRegions with DataPolicy.NORMAL, it throws UnsupportedOperationException. For
* DistributedRegions with DataPolicy.EMPTY, execute the function on any random member which has
* DataPolicy.REPLICATE <br>
* . For DistributedRegions with DataPolicy.REPLICATE, execute the function locally. For Regions
* with DataPolicy.PARTITION, it executes on members where the data resides as specified by the
* filter.
*
* @return Execution
* @throws FunctionException if the region passed in is null
* @since GemFire 6.0
*/
public Execution onRegion(Region region) {
if (region == null) {
throw new FunctionException(LocalizedStrings.FunctionService_0_PASSED_IS_NULL.toLocalizedString("Region instance "));
}
ProxyCache proxyCache = null;
String poolName = region.getAttributes().getPoolName();
if (poolName != null) {
Pool pool = PoolManager.find(poolName);
if (pool.getMultiuserAuthentication()) {
if (region instanceof ProxyRegion) {
ProxyRegion proxyRegion = (ProxyRegion) region;
region = proxyRegion.getRealRegion();
proxyCache = proxyRegion.getAuthenticatedCache();
} else {
throw new UnsupportedOperationException();
}
}
}
if (isClientRegion(region)) {
return new ServerRegionFunctionExecutor(region, proxyCache);
}
if (PartitionRegionHelper.isPartitionedRegion(region)) {
return new PartitionedRegionFunctionExecutor(region);
}
return new DistributedRegionFunctionExecutor(region);
}
use of org.apache.geode.cache.client.internal.ProxyCache in project geode by apache.
the class ClientCacheFactoryJUnitTest method test003DPmultiplePool.
/**
* Make sure if we have more than one pool that we do not have a default
*/
@Test
public void test003DPmultiplePool() throws Exception {
Properties dsProps = new Properties();
dsProps.setProperty(MCAST_PORT, "0");
DistributedSystem ds = DistributedSystem.connect(dsProps);
PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 7777).create("p7");
PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 6666).create("p6");
this.cc = new ClientCacheFactory().create();
GemFireCacheImpl gfc = (GemFireCacheImpl) this.cc;
assertEquals(true, gfc.isClient());
Pool defPool = gfc.getDefaultPool();
assertEquals(null, defPool);
// exists that is not multiuser enabled
try {
Properties suProps = new Properties();
suProps.setProperty("user", "foo");
RegionService cc = this.cc.createAuthenticatedView(suProps);
fail("expected IllegalStateException");
} catch (IllegalStateException ignore) {
}
// however we should be to to create it by configuring a pool
{
Properties suProps = new Properties();
suProps.setProperty("user", "foo");
Pool pool = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), CacheServer.DEFAULT_PORT).setMultiuserAuthentication(true).create("pool1");
RegionService cc = this.cc.createAuthenticatedView(suProps, pool.getName());
ProxyCache pc = (ProxyCache) cc;
UserAttributes ua = pc.getUserAttributes();
Pool proxyDefPool = ua.getPool();
assertEquals(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT)), proxyDefPool.getServers());
assertEquals(true, proxyDefPool.getMultiuserAuthentication());
}
}
use of org.apache.geode.cache.client.internal.ProxyCache in project geode by apache.
the class ClientCacheFactoryJUnitTest method test002DPsinglePool.
/**
* Make sure if we have a single pool that it will be used as the default
*/
@Test
public void test002DPsinglePool() throws Exception {
Properties dsProps = new Properties();
dsProps.setProperty(MCAST_PORT, "0");
DistributedSystem ds = DistributedSystem.connect(dsProps);
Pool p = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), 7777).create("singlePool");
this.cc = new ClientCacheFactory().create();
GemFireCacheImpl gfc = (GemFireCacheImpl) this.cc;
assertEquals(true, gfc.isClient());
Pool defPool = gfc.getDefaultPool();
assertEquals(p, defPool);
// exists that is not multiuser enabled
try {
Properties suProps = new Properties();
suProps.setProperty("user", "foo");
RegionService cc = this.cc.createAuthenticatedView(suProps);
fail("expected IllegalStateException");
} catch (IllegalStateException ignore) {
}
// however we should be to to create it by configuring a pool
{
Properties suProps = new Properties();
suProps.setProperty("user", "foo");
Pool pool = PoolManager.createFactory().addServer(InetAddress.getLocalHost().getHostName(), CacheServer.DEFAULT_PORT).setMultiuserAuthentication(true).create("pool1");
RegionService cc = this.cc.createAuthenticatedView(suProps, pool.getName());
ProxyCache pc = (ProxyCache) cc;
UserAttributes ua = pc.getUserAttributes();
Pool proxyDefPool = ua.getPool();
assertEquals(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT)), proxyDefPool.getServers());
assertEquals(true, proxyDefPool.getMultiuserAuthentication());
}
}
Aggregations