use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class PdxLocalQueryVersionedClassDUnitTest method testIsRemoteFlagForRemoteQueries.
/**
* Testing the isRemote flag which could be inconsistent when bind queries are being executed in
* multiple threads. Bug #49662 is caused because of this inconsistent behavior.
*
* @throws Exception
*/
@Test
public void testIsRemoteFlagForRemoteQueries() throws Exception {
final Host host = Host.getHost(0);
final VM server = host.getVM(0);
final VM client = host.getVM(1);
final int numberOfEntries = 1000;
final String name = "/" + regionName;
final String query = "select distinct * from " + name + " where id > $1 and id < $2 and status = 'active'";
// Start server
final int port1 = (Integer) server.invoke(new SerializableCallable("Create Server") {
@Override
public Object call() throws Exception {
Region r1 = getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
CacheServer server = getCache().addCacheServer();
int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite();
server.setPort(port);
server.start();
return port;
}
});
// Start client and put version1 objects on server
// Server does not have version1 classes in classpath
client.invoke(new SerializableCallable("Create client") {
@Override
public Object call() throws Exception {
ClientCacheFactory cf = new ClientCacheFactory();
cf.addPoolServer(NetworkUtils.getServerHostName(server.getHost()), port1);
ClientCache cache = getClientCache(cf);
Region region = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regionName);
for (int i = 0; i < numberOfEntries; i++) {
PdxInstanceFactory pdxInstanceFactory = PdxInstanceFactoryImpl.newCreator("PdxVersionedNewPortfolio", false);
pdxInstanceFactory.writeInt("id", i);
pdxInstanceFactory.writeString("status", (i % 2 == 0 ? "active" : "inactive"));
PdxInstance pdxInstance = pdxInstanceFactory.create();
region.put("key-" + i, pdxInstance);
}
return null;
}
});
// Execute same query remotely from client using 2 threads
// Since this is a bind query, the query object will be shared
// between the 2 threads.
AsyncInvocation a1 = client.invokeAsync(new SerializableCallable("Query from client") {
@Override
public Object call() throws Exception {
QueryService qs = null;
SelectResults sr = null;
// Execute query remotely
try {
qs = getCache().getQueryService();
} catch (Exception e) {
Assert.fail("Failed to get QueryService.", e);
}
try {
for (int i = 0; i < 100; i++) {
sr = (SelectResults) qs.newQuery(query).execute(new Object[] { 1, 1000 });
}
Assert.assertTrue("Size of resultset should be greater than 0 for query: " + query, sr.size() > 0);
} catch (Exception e) {
Assert.fail("Failed executing query " + query, e);
}
return null;
}
});
AsyncInvocation a2 = client.invokeAsync(new SerializableCallable("Query from client") {
@Override
public Object call() throws Exception {
QueryService qs = null;
SelectResults sr = null;
// Execute query remotely
try {
qs = getCache().getQueryService();
} catch (Exception e) {
Assert.fail("Failed to get QueryService.", e);
}
try {
for (int i = 0; i < 100; i++) {
sr = (SelectResults) qs.newQuery(query).execute(new Object[] { 997, 1000 });
}
Assert.assertTrue("Size of resultset should be greater than 0 for query: " + query, sr.size() > 0);
} catch (Exception e) {
Assert.fail("Failed executing query " + query, e);
}
return null;
}
});
ThreadUtils.join(a1, 60 * 1000);
ThreadUtils.join(a2, 60 * 1000);
if (a1.exceptionOccurred()) {
Assert.fail("Failed query execution " + a1.getException().getMessage());
}
if (a2.exceptionOccurred()) {
Assert.fail("Failed query execution " + a2.getException());
}
this.closeClient(client);
this.closeClient(server);
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class RestAPIsWithSSLDUnitTest method createRegionInClientCache.
private void createRegionInClientCache() {
ClientCache clientCache = ClientCacheFactory.getAnyInstance();
assertNotNull(clientCache);
clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(PEOPLE_REGION_NAME);
clientCache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(REGION_NAME);
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class RestAPIsAndInterOpsDUnitTest method createRegionInClientCache.
public void createRegionInClientCache() {
ClientCache cache = GemFireCacheImpl.getInstance();
assertNotNull(cache);
ClientRegionFactory<String, Object> crf = cache.createClientRegionFactory(ClientRegionShortcut.PROXY);
Region<String, Object> region = crf.create(PEOPLE_REGION_NAME);
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class QueryParamsAuthorizationDUnitTest method testQueryParamsInAuthCallback.
@Ignore("Bug 51079")
@Test
public void testQueryParamsInAuthCallback() throws Exception {
final Host host = Host.getHost(0);
final VM server1 = host.getVM(0);
final VM client = host.getVM(1);
// create servers and regions
final int port = (Integer) server1.invoke(new SerializableCallable("Create Server1") {
@Override
public Object call() throws Exception {
CacheFactory cf = new CacheFactory().set(MCAST_PORT, "0").set(SECURITY_CLIENT_ACCESSOR, "org.apache.geode.cache.query.dunit.QueryAuthorization.create").set(SECURITY_CLIENT_AUTHENTICATOR, DummyAuthenticator.class.getName() + ".create");
Cache cache = getCache(cf);
cache.createRegionFactory(RegionShortcut.REPLICATE).create(regName);
CacheServer server = cache.addCacheServer();
int port = AvailablePortHelper.getRandomAvailablePortForDUnitSite();
server.setPort(port);
server.start();
return port;
}
});
// create client
client.invoke(new SerializableCallable("Create client") {
@Override
public Object call() throws Exception {
ClientCacheFactory ccf = new ClientCacheFactory().addPoolServer(NetworkUtils.getServerHostName(server1.getHost()), port).set(SECURITY_CLIENT_AUTH_INIT, UserPasswordAuthInit.class.getName() + ".create").set(SECURITY_PREFIX + "username", "root").set(SECURITY_PREFIX + "password", "root");
ClientCache cache = getClientCache(ccf);
Region r1 = cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName);
for (int i = 0; i < 20; i++) {
r1.put("key-" + i, new Portfolio(i));
}
QueryService qs = cache.getQueryService();
Object[] params = new Object[] { "active", 0 };
SelectResults sr = (SelectResults) qs.newQuery("select * from " + r1.getFullPath() + " where status = $1 and ID > $2 ").execute(params);
assertTrue("Result size should be greater than 0 ", sr.size() > 0);
return null;
}
});
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class QueryUsingFunctionContextDUnitTest method createProxyRegs.
private void createProxyRegs() {
ClientCache cache = (ClientCache) CacheFactory.getAnyInstance();
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(repRegionName);
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(localRegionName);
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(PartitionedRegionName1);
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(PartitionedRegionName2);
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(PartitionedRegionName3);
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(PartitionedRegionName4);
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(PartitionedRegionName5);
}
Aggregations