use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class RollingUpgrade2DUnitTest method createClientRegion.
// Assumes a client cache is passed
public static void createClientRegion(GemFireCache cache, String regionName, ClientRegionShortcut shortcut) throws Exception {
ClientRegionFactory rf = ((ClientCache) cache).createClientRegionFactory(shortcut);
rf.create(regionName);
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class RegionCreateDestroyDUnitTest method testCreateDestroyReservedRegion.
// GEODE-1878
@Category(FlakyTest.class)
@Test
public void testCreateDestroyReservedRegion() throws InterruptedException {
Cache serverCache = getCache();
try {
serverCache.createRegionFactory(RegionShortcut.REPLICATE).create(RESERVED_REGION_NAME);
fail("Should have thrown an IllegalArgumentException");
} catch (IllegalArgumentException arg) {
assertEquals("Region names may not begin with a double-underscore: __ReservedRegion", arg.getMessage());
}
try {
startServer(serverCache);
} catch (IOException e) {
fail(e.getMessage());
}
try {
client1.invoke(() -> {
ClientCache cache = new ClientCacheFactory(createClientProperties()).setPoolSubscriptionEnabled(true).addPoolServer("localhost", serverPort).create();
try {
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(RESERVED_REGION_NAME);
fail("Should have thrown an IllegalArgumentException");
} catch (IllegalArgumentException e) {
assertEquals("Region names may not begin with a double-underscore: __ReservedRegion", e.getMessage());
}
});
} catch (RMIException rmi) {
rmi.getCause();
}
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class RegionCreateDestroyDUnitTest method testCreateDestroyValidRegion.
// GEODE-1922
@Category(FlakyTest.class)
@Test
public void testCreateDestroyValidRegion() throws InterruptedException {
Cache serverCache = getCache();
serverCache.createRegionFactory(RegionShortcut.REPLICATE).create(GOOD_REGION_NAME);
try {
startServer(serverCache);
} catch (IOException e) {
fail(e.getMessage());
}
client1.invoke(() -> {
ClientCache cache = new ClientCacheFactory(createClientProperties()).setPoolSubscriptionEnabled(true).addPoolServer("localhost", serverPort).create();
Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(GOOD_REGION_NAME);
region.destroyRegion();
assertThat(region.isDestroyed()).isTrue();
});
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class QueryDataInconsistencyDUnitTest method createProxyRegs.
private void createProxyRegs() {
ClientCache cache = (ClientCache) CacheFactory.getAnyInstance();
cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(repRegionName);
/*
* cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create( PartitionedRegionName1);
*/
}
use of org.apache.geode.cache.client.ClientCache in project geode by apache.
the class PdxQueryDUnitTest method testPdxInstanceNoFieldNoMethod.
/**
* Test to query a field that is not present in the Pdx object Also the implicit method is absent
* in the class
*
* @throws CacheException
*/
@Test
public void testPdxInstanceNoFieldNoMethod() throws CacheException {
final Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm3 = host.getVM(3);
final int numberOfEntries = 10;
final String name = "/" + regionName;
final String[] qs = { "select * from " + name + " where pdxStatus = 'active'", "select pdxStatus from " + name + " where id > 4" };
// Start server1
final int port1 = (Integer) vm0.invoke(new SerializableCallable("Create Server1") {
@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;
}
});
// create client and load only version 1 objects with no pdxStatus field
vm3.invoke(new SerializableCallable("Create client") {
@Override
public Object call() throws Exception {
ClientCacheFactory cf = new ClientCacheFactory();
cf.addPoolServer(NetworkUtils.getServerHostName(vm0.getHost()), port1);
ClientCache cache = getClientCache(cf);
Region region = cache.createClientRegionFactory(ClientRegionShortcut.PROXY).create(regionName);
// Load version 1 objects
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;
}
});
// Version1 class loader
vm3.invoke(new SerializableCallable("Create client") {
@Override
public Object call() throws Exception {
// Load version 1 classloader
QueryService remoteQueryService = null;
// Execute query remotely
try {
remoteQueryService = getCache().getQueryService();
} catch (Exception e) {
Assert.fail("Failed to get QueryService.", e);
}
for (int i = 0; i < qs.length; i++) {
try {
SelectResults sr = (SelectResults) remoteQueryService.newQuery(qs[i]).execute();
if (i == 1) {
assertEquals(5, sr.size());
for (Object o : sr) {
if (!(o instanceof Undefined)) {
fail("Result should be Undefined and not " + o.getClass());
}
}
} else {
assertEquals(0, sr.size());
}
} catch (Exception e) {
Assert.fail("Failed executing " + qs[i], e);
}
}
return null;
}
});
Invoke.invokeInEveryVM(DistributedTestCase.class, "disconnectFromDS");
}
Aggregations