use of org.apache.geode.internal.cache.GemFireCacheImpl 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.internal.cache.GemFireCacheImpl 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());
}
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class ClientCacheFactoryJUnitTest method test000Defaults.
@Test
public void test000Defaults() throws Exception {
this.cc = new ClientCacheFactory().create();
GemFireCacheImpl gfc = (GemFireCacheImpl) this.cc;
assertEquals(true, gfc.isClient());
Properties dsProps = this.cc.getDistributedSystem().getProperties();
assertEquals("0", dsProps.getProperty(MCAST_PORT));
assertEquals("", dsProps.getProperty(LOCATORS));
Pool defPool = gfc.getDefaultPool();
assertEquals("DEFAULT", defPool.getName());
assertEquals(new ArrayList(), defPool.getLocators());
assertEquals(Collections.singletonList(new InetSocketAddress(InetAddress.getLocalHost(), CacheServer.DEFAULT_PORT)), defPool.getServers());
ClientCache cc2 = new ClientCacheFactory().create();
if (cc2 != this.cc) {
fail("expected cc2 and cc to be == " + cc2 + this.cc);
}
try {
new ClientCacheFactory().set(LOG_LEVEL, "severe").create();
fail("expected create to fail");
} catch (IllegalStateException expected) {
}
try {
new ClientCacheFactory().addPoolLocator("127.0.0.1", 36666).create();
fail("expected create to fail");
} catch (IllegalStateException expected) {
}
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class SelectStarQueryDUnitTest method testSelectStarQueryForPdxObjects.
@Test
public void testSelectStarQueryForPdxObjects() throws Exception {
final Host host = Host.getHost(0);
final VM server1 = host.getVM(0);
final VM client = host.getVM(3);
// create servers and regions
final int port1 = startReplicatedCacheServer(server1);
server1.invoke(new SerializableCallable("Set observer") {
@Override
public Object call() throws Exception {
oldObserver = QueryObserverHolder.setInstance(new QueryResultTrackingObserver());
return null;
}
});
// create client
client.invoke(new SerializableCallable("Create client") {
@Override
public Object call() throws Exception {
ClientCacheFactory cf = new ClientCacheFactory();
cf.addPoolServer(getServerHostName(server1.getHost()), port1);
ClientCache cache = getClientCache(cf);
cache.createClientRegionFactory(ClientRegionShortcut.CACHING_PROXY).create(regName);
return null;
}
});
// Update with serialized PortfolioPdx objects
client.invoke(new SerializableCallable("Put objects") {
@Override
public Object call() throws Exception {
Region r1 = getRootRegion(regName);
for (int i = 0; i < 20; i++) {
r1.put("key-" + i, new PortfolioPdx(i));
}
return null;
}
});
// query remotely from client
client.invoke(new SerializableCallable("Query") {
@Override
public Object call() throws Exception {
getLogWriter().info("Querying remotely from client");
QueryService localQS = null;
QueryService remoteQS = null;
try {
localQS = ((ClientCache) getCache()).getLocalQueryService();
remoteQS = ((ClientCache) getCache()).getQueryService();
} catch (Exception e) {
fail("Exception getting query service ", e);
}
SelectResults res = null;
SelectResults[][] sr = new SelectResults[1][2];
for (int i = 0; i < queries.length; i++) {
try {
res = (SelectResults) localQS.newQuery(queries[i]).execute();
sr[0][0] = res;
res = (SelectResults) remoteQS.newQuery(queries[i]).execute();
sr[0][1] = res;
CacheUtils.compareResultsOfWithAndWithoutIndex(sr);
} catch (Exception e) {
fail("Error executing query: " + queries[i], e);
}
assertEquals(resultSize[i], res.size());
if (i == 3) {
int cnt = ((Integer) res.iterator().next());
assertEquals(20, cnt);
} else {
for (Object rs : res) {
if (rs instanceof StructImpl) {
for (Object obj : ((StructImpl) rs).getFieldValues()) {
if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + obj.getClass());
}
}
} else if (rs instanceof PortfolioPdx) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
}
}
}
}
return null;
}
});
// verify if objects iterated by query are serialized
server1.invoke(new SerializableCallable("Get observer") {
@Override
public Object call() throws Exception {
QueryObserver observer = QueryObserverHolder.getInstance();
assertTrue(QueryObserverHolder.hasObserver());
assertTrue(observer instanceof QueryResultTrackingObserver);
QueryResultTrackingObserver resultObserver = (QueryResultTrackingObserver) observer;
assertTrue(resultObserver.isObjectSerialized());
return null;
}
});
// verify if objects returned by local server query are not serialized
server1.invoke(new SerializableCallable("Query") {
@Override
public Object call() throws Exception {
QueryObserver observer = QueryObserverHolder.setInstance(new QueryResultTrackingObserver());
QueryService qs = null;
try {
qs = getCache().getQueryService();
} catch (Exception e) {
fail("Exception getting query service ", e);
}
SelectResults res = null;
for (int i = 0; i < queries.length; i++) {
try {
res = (SelectResults) qs.newQuery(queries[i]).execute();
} catch (Exception e) {
fail("Error executing query: " + queries[i], e);
}
assertEquals(resultSize[i], res.size());
if (i == 3) {
int cnt = ((Integer) res.iterator().next());
assertEquals(20, cnt);
} else {
for (Object rs : res) {
if (rs instanceof StructImpl) {
for (Object obj : ((StructImpl) rs).getFieldValues()) {
if (obj instanceof PortfolioPdx || obj instanceof PositionPdx) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + obj.getClass());
}
}
} else if (rs instanceof PortfolioPdx) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PortfolioPdx and not " + rs.getClass());
}
}
}
}
observer = QueryObserverHolder.getInstance();
assertTrue(QueryObserverHolder.hasObserver());
assertTrue(observer instanceof QueryResultTrackingObserver);
QueryResultTrackingObserver resultObserver = (QueryResultTrackingObserver) observer;
assertFalse(resultObserver.isObjectSerialized());
QueryObserverHolder.setInstance(oldObserver);
return null;
}
});
// verify if Pdx instances are returned by local server query
// if read-serialized is set true
server1.invoke(new SerializableCallable("Query") {
@Override
public Object call() throws Exception {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
cache.setReadSerialized(true);
QueryService qs = null;
try {
qs = getCache().getQueryService();
} catch (Exception e) {
fail("Exception getting query service ", e);
}
SelectResults res = null;
for (int i = 0; i < queries.length; i++) {
try {
res = (SelectResults) qs.newQuery(queries[i]).execute();
} catch (Exception e) {
fail("Error executing query: " + queries[i], e);
}
assertEquals(resultSize[i], res.size());
if (i == 3) {
int cnt = ((Integer) res.iterator().next());
assertEquals(20, cnt);
} else {
for (Object rs : res) {
if (rs instanceof StructImpl) {
for (Object obj : ((StructImpl) rs).getFieldValues()) {
if (obj instanceof PdxInstance) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PdxInstance and not " + obj.getClass());
}
}
} else if (rs instanceof PdxInstance) {
} else {
fail("Result objects for remote client query: " + queries[i] + " should be instance of PdxInstance and not " + rs.getClass());
}
}
}
}
return null;
}
});
closeCache(client);
closeCache(server1);
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class CacheXml66DUnitTest method testLOCAL_PERSISTENT_OVERFLOW.
@Test
public void testLOCAL_PERSISTENT_OVERFLOW() throws Exception {
CacheCreation cache = new CacheCreation();
RegionCreation root = (RegionCreation) cache.createRegion("cpolocal", "LOCAL_PERSISTENT_OVERFLOW");
testXml(cache);
GemFireCacheImpl c = (GemFireCacheImpl) getCache();
Region r = c.getRegion("cpolocal");
assertNotNull(r);
RegionAttributes ra = r.getAttributes();
assertEquals(DataPolicy.PERSISTENT_REPLICATE, ra.getDataPolicy());
assertEquals(Scope.LOCAL, ra.getScope());
assertEquals(EvictionAttributes.createLRUHeapAttributes(null, EvictionAction.OVERFLOW_TO_DISK), ra.getEvictionAttributes());
assertEquals(LocalRegion.DEFAULT_HEAPLRU_EVICTION_HEAP_PERCENTAGE, c.getResourceManager().getEvictionHeapPercentage(), 0);
}
Aggregations