use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class PdxStringQueryDUnitTest method testPartitionRegionNoIndex.
@Test
public void testPartitionRegionNoIndex() throws CacheException {
final Host host = Host.getHost(0);
VM server0 = host.getVM(0);
VM server1 = host.getVM(1);
VM server2 = host.getVM(2);
VM client = host.getVM(3);
final int numberOfEntries = 10;
final boolean isPr = true;
// Start server1 and create index
server0.invoke(new CacheSerializableRunnable("Create Server1") {
public void run2() throws CacheException {
configAndStartBridgeServer(isPr, false, false);
// create a local query service
QueryService localQueryService = null;
try {
localQueryService = getCache().getQueryService();
} catch (Exception e) {
Assert.fail("Failed to get QueryService.", e);
}
Index index = null;
// created
try {
index = localQueryService.createIndex("secIdIndex", "pos.secIdIndexed", regName + " p, p.positions.values pos");
if (index instanceof PartitionedIndex) {
for (Object o : ((PartitionedIndex) index).getBucketIndexes()) {
if (!(o instanceof RangeIndex)) {
fail("RangeIndex Index should have been created instead of " + index.getClass());
}
}
} else {
fail("Partitioned index expected");
}
} catch (Exception ex) {
fail("Failed to create index." + ex.getMessage());
}
}
});
// Start server2
server1.invoke(new CacheSerializableRunnable("Create Server2") {
public void run2() throws CacheException {
configAndStartBridgeServer(isPr, false, false);
Region region = getRootRegion().getSubregion(regionName);
}
});
// Start server3
server2.invoke(new CacheSerializableRunnable("Create Server3") {
public void run2() throws CacheException {
configAndStartBridgeServer(isPr, false, false);
Region region = getRootRegion().getSubregion(regionName);
}
});
// Client pool.
final int port0 = server0.invoke(() -> PdxStringQueryDUnitTest.getCacheServerPort());
final int port1 = server1.invoke(() -> PdxStringQueryDUnitTest.getCacheServerPort());
final int port2 = server2.invoke(() -> PdxStringQueryDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server0.getHost());
// Create client pool.
final String poolName = "testClientServerQueryPool";
createPool(client, poolName, new String[] { host0 }, new int[] { port0, port1, port2 }, true);
// Create client region and put PortfolioPdx objects (PdxInstances)
client.invoke(new CacheSerializableRunnable("Create client") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
ClientServerTestCase.configureConnectionPool(factory, host0, port1, -1, true, -1, -1, null);
Region region = createRegion(regionName, rootRegionName, factory.create());
LogWriterUtils.getLogWriter().info("Put PortfolioPdx");
for (int i = 0; i < numberOfEntries; i++) {
region.put("key-" + i, new PortfolioPdx(i));
}
}
});
// Execute queries from client to server and locally on client
SerializableRunnable executeQueries = new CacheSerializableRunnable("Execute queries") {
public void run2() throws CacheException {
QueryService remoteQueryService = null;
QueryService localQueryService = null;
SelectResults[][] rs = new SelectResults[1][2];
SelectResults[] resWithoutIndexRemote = new SelectResults[queryString.length];
SelectResults[] resWithIndexRemote = new SelectResults[queryString.length];
SelectResults[] resWithoutIndexLocal = new SelectResults[queryString.length];
SelectResults[] resWithIndexLocal = new SelectResults[queryString.length];
try {
remoteQueryService = (PoolManager.find(poolName)).getQueryService();
localQueryService = getCache().getQueryService();
} catch (Exception e) {
Assert.fail("Failed to get QueryService.", e);
}
for (int i = 0; i < queryString.length; i++) {
try {
LogWriterUtils.getLogWriter().info("### Executing Query on remote server:" + queryString[i]);
Query query = remoteQueryService.newQuery(queryString[i]);
rs[0][0] = (SelectResults) query.execute();
resWithoutIndexRemote[i] = rs[0][0];
LogWriterUtils.getLogWriter().info("RR remote no index size of resultset: " + rs[0][0].size() + " for query: " + queryString[i]);
;
checkForPdxString(rs[0][0].asList(), queryString[i]);
LogWriterUtils.getLogWriter().info("### Executing Query locally on client:" + queryString[i]);
query = localQueryService.newQuery(queryString[i]);
rs[0][1] = (SelectResults) query.execute();
resWithoutIndexLocal[i] = rs[0][1];
LogWriterUtils.getLogWriter().info("isPR: " + isPr + " client local indexType:no index size of resultset: " + rs[0][1].size() + " for query: " + queryString[i]);
;
checkForPdxString(rs[0][1].asList(), queryString[i]);
} catch (Exception e) {
Assert.fail("Failed executing " + queryString[i], e);
}
try {
// to compare remote query results with and without index
LogWriterUtils.getLogWriter().info("### Executing Query on remote server for region2:" + queryString2[i]);
Query query = remoteQueryService.newQuery(queryString2[i]);
resWithIndexRemote[i] = (SelectResults) query.execute();
LogWriterUtils.getLogWriter().info("isPR: " + isPr + " remote region2 size of resultset: " + resWithIndexRemote[i].size() + " for query: " + queryString2[i]);
;
checkForPdxString(resWithIndexRemote[i].asList(), queryString2[i]);
// to compare local query results with and without index
LogWriterUtils.getLogWriter().info("### Executing Query on local for region2:" + queryString2[i]);
query = localQueryService.newQuery(queryString2[i]);
resWithIndexLocal[i] = (SelectResults) query.execute();
LogWriterUtils.getLogWriter().info("isPR: " + isPr + " local region2 size of resultset: " + resWithIndexLocal[i].size() + " for query: " + queryString2[i]);
;
checkForPdxString(resWithIndexLocal[i].asList(), queryString2[i]);
} catch (Exception e) {
Assert.fail("Failed executing " + queryString2[i], e);
}
if (i < orderByQueryIndex) {
// Compare local and remote query results.
if (!compareResultsOfWithAndWithoutIndex(rs)) {
LogWriterUtils.getLogWriter().info("result0=" + rs[0][0].asList());
LogWriterUtils.getLogWriter().info("result1=" + rs[0][1].asList());
fail("Local and Remote Query Results are not matching for query :" + queryString[i]);
}
} else {
// compare the order of results returned
compareResultsOrder(rs, isPr);
}
}
for (int i = 0; i < queryString.length; i++) {
rs[0][0] = resWithoutIndexRemote[i];
rs[0][1] = resWithIndexRemote[i];
if (i < orderByQueryIndex) {
// Compare local and remote query results.
if (!compareResultsOfWithAndWithoutIndex(rs)) {
fail("Results with and without index are not matching for query :" + queryString2[i]);
}
} else {
// compare the order of results returned
compareResultsOrder(rs, isPr);
}
}
for (int i = 0; i < queryString.length; i++) {
rs[0][0] = resWithoutIndexLocal[i];
rs[0][1] = resWithIndexLocal[i];
if (i < orderByQueryIndex) {
// Compare local and remote query results.
if (!compareResultsOfWithAndWithoutIndex(rs)) {
fail("Results with and without index are not matching for query :" + queryString2[i]);
}
} else {
// compare the order of results returned
compareResultsOrder(rs, isPr);
}
}
}
};
client.invoke(executeQueries);
// Put Non Pdx objects on server execute queries locally
server0.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(regionName);
LogWriterUtils.getLogWriter().info("Put Objects locally on server");
for (int i = numberOfEntries; i < numberOfEntries * 2; i++) {
region.put("key-" + i, new Portfolio(i));
}
QueryService localQueryService = getCache().getQueryService();
// Query server1 locally to check if PdxString is not being returned
for (int i = 0; i < queryString.length; i++) {
try {
LogWriterUtils.getLogWriter().info("### Executing Query locally on server:" + queryString[i]);
SelectResults rs = (SelectResults) localQueryService.newQuery(queryString[i]).execute();
LogWriterUtils.getLogWriter().info("PR server local indexType:no size of resultset: " + rs.size() + " for query: " + queryString[i]);
// The results should not be PdxString
checkForPdxString(rs.asList(), queryString[i]);
} catch (Exception e) {
Assert.fail("Failed executing " + queryString[i], e);
}
try {
SelectResults rs = (SelectResults) localQueryService.newQuery(queryString2[i]).execute();
LogWriterUtils.getLogWriter().info("PR server local indexType: no size of resultset: " + rs.size() + " for query: " + queryString2[i]);
// The results should not be PdxString
checkForPdxString(rs.asList(), queryString2[i]);
} catch (Exception e) {
Assert.fail("Failed executing " + queryString2[i], e);
}
}
}
});
// test for readSerialized flag
server0.invoke(new CacheSerializableRunnable("Create Bridge Server") {
public void run2() throws CacheException {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
cache.setReadSerialized(true);
QueryService localQueryService = getCache().getQueryService();
// Query server1 locally to check if PdxString is not being returned
for (int i = 0; i < queryString.length; i++) {
try {
LogWriterUtils.getLogWriter().info("### Executing Query locally on server:" + queryString[i]);
SelectResults rs = (SelectResults) localQueryService.newQuery(queryString[i]).execute();
LogWriterUtils.getLogWriter().info("isPR: " + isPr + " server local readSerializedTrue: indexType: no index size of resultset: " + rs.size() + " for query: " + queryString[i]);
// The results should not be PdxString
checkForPdxString(rs.asList(), queryString[i]);
} catch (Exception e) {
Assert.fail("Failed executing " + queryString[i], e);
}
}
}
});
// test for readSerialized flag on client
client.invoke(new CacheSerializableRunnable("Create client") {
public void run2() throws CacheException {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
cache.setReadSerialized(true);
QueryService remoteQueryService = (PoolManager.find(poolName)).getQueryService();
// Query server1 remotely to check if PdxString is not being returned
for (int i = 0; i < queryString.length; i++) {
try {
LogWriterUtils.getLogWriter().info("### Executing Query locally on server:" + queryString[i]);
SelectResults rs = (SelectResults) remoteQueryService.newQuery(queryString[i]).execute();
LogWriterUtils.getLogWriter().info("RR server remote readSerializedTrue: indexType:no index size of resultset: " + rs.size() + " for query: " + queryString[i]);
// The results should not be PdxString
checkForPdxString(rs.asList(), queryString[i]);
} catch (Exception e) {
Assert.fail("Failed executing " + queryString[i], e);
}
}
}
});
closeClient(server2);
closeClient(client);
closeClient(server1);
closeClient(server0);
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class RegionAttributesCreation method inheritAttributes.
void inheritAttributes(Cache cache, boolean setDefaultPool) {
if (this.refid == null) {
// No attributes to inherit
if (setDefaultPool && this.requiresPoolName && !hasPoolName()) {
String defaultPoolName = null;
if (cache instanceof GemFireCacheImpl) {
InternalClientCache gfc = (InternalClientCache) cache;
if (gfc.getDefaultPool() != null) {
defaultPoolName = gfc.getDefaultPool().getName();
}
} else if (cache instanceof ClientCacheCreation) {
ClientCacheCreation ccc = (ClientCacheCreation) cache;
defaultPoolName = ccc.getDefaultPoolName();
}
if (defaultPoolName != null) {
setPoolName(defaultPoolName);
}
}
return;
}
RegionAttributes parent = cache.getRegionAttributes(this.refid);
if (parent == null) {
throw new IllegalStateException(LocalizedStrings.RegionAttributesCreation_CANNOT_REFERENCE_NONEXISTING_REGION_ATTRIBUTES_NAMED_0.toLocalizedString(this.refid));
}
final boolean parentIsUserSpecified = parent instanceof UserSpecifiedRegionAttributes;
final UserSpecifiedRegionAttributes parentWithHas;
if (parentIsUserSpecified) {
parentWithHas = (UserSpecifiedRegionAttributes) parent;
} else {
parentWithHas = null;
}
if (parentWithHas != null) {
if (setDefaultPool && parentWithHas.requiresPoolName) {
this.requiresPoolName = true;
if (!hasPoolName()) {
String defaultPoolName = null;
if (cache instanceof GemFireCacheImpl) {
InternalClientCache gfc = (InternalClientCache) cache;
if (gfc.getDefaultPool() != null) {
defaultPoolName = gfc.getDefaultPool().getName();
}
} else if (cache instanceof ClientCacheCreation) {
ClientCacheCreation ccc = (ClientCacheCreation) cache;
defaultPoolName = ccc.getDefaultPoolName();
}
if (defaultPoolName != null) {
setPoolName(defaultPoolName);
}
}
}
}
// Inherit attributes that are not overridden
if (!hasCacheListeners()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasCacheListeners()) {
initCacheListeners(parent.getCacheListeners());
}
} else {
initCacheListeners(parent.getCacheListeners());
}
}
if (!hasGatewaySenderId()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasGatewaySenderId()) {
initGatewaySenders(parent.getGatewaySenderIds());
}
} else {
initGatewaySenders(parent.getGatewaySenderIds());
}
}
if (!hasAsyncEventListeners()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasAsyncEventListeners()) {
initAsyncEventQueues(parent.getAsyncEventQueueIds());
}
} else {
initAsyncEventQueues(parent.getAsyncEventQueueIds());
}
}
if (!hasCacheLoader()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasCacheLoader()) {
setCacheLoader(parent.getCacheLoader());
}
} else {
setCacheLoader(parent.getCacheLoader());
}
}
if (!hasCacheWriter()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasCacheWriter()) {
setCacheWriter(parent.getCacheWriter());
}
} else {
setCacheWriter(parent.getCacheWriter());
}
}
if (!hasEntryIdleTimeout()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasEntryIdleTimeout()) {
setEntryIdleTimeout(parent.getEntryIdleTimeout());
}
} else {
setEntryIdleTimeout(parent.getEntryIdleTimeout());
}
}
if (!hasCustomEntryIdleTimeout()) {
setCustomEntryIdleTimeout(parent.getCustomEntryIdleTimeout());
}
if (!hasEntryTimeToLive()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasEntryTimeToLive()) {
setEntryTimeToLive(parent.getEntryTimeToLive());
}
} else {
setEntryTimeToLive(parent.getEntryTimeToLive());
}
}
if (!hasCustomEntryTimeToLive()) {
setCustomEntryTimeToLive(parent.getCustomEntryTimeToLive());
}
if (!hasInitialCapacity()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasInitialCapacity()) {
setInitialCapacity(parent.getInitialCapacity());
}
} else {
setInitialCapacity(parent.getInitialCapacity());
}
}
if (!hasKeyConstraint()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasKeyConstraint()) {
setKeyConstraint(parent.getKeyConstraint());
}
} else {
setKeyConstraint(parent.getKeyConstraint());
}
}
if (!hasValueConstraint()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasValueConstraint()) {
setValueConstraint(parent.getValueConstraint());
}
} else {
setValueConstraint(parent.getValueConstraint());
}
}
if (!hasLoadFactor()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasLoadFactor()) {
setLoadFactor(parent.getLoadFactor());
}
} else {
setLoadFactor(parent.getLoadFactor());
}
}
if (!hasRegionIdleTimeout()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasRegionIdleTimeout()) {
setRegionIdleTimeout(parent.getRegionIdleTimeout());
}
} else {
setRegionIdleTimeout(parent.getRegionIdleTimeout());
}
}
if (!hasRegionTimeToLive()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasRegionTimeToLive()) {
setRegionTimeToLive(parent.getRegionTimeToLive());
}
} else {
setRegionTimeToLive(parent.getRegionTimeToLive());
}
}
if (!hasScope()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasScope()) {
setScope(parent.getScope());
}
} else {
setScope(parent.getScope());
}
}
if (!hasStatisticsEnabled()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasStatisticsEnabled()) {
setStatisticsEnabled(parent.getStatisticsEnabled());
}
} else {
setStatisticsEnabled(parent.getStatisticsEnabled());
}
}
if (!hasIgnoreJTA()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasIgnoreJTA()) {
setIgnoreJTA(parent.getIgnoreJTA());
}
} else {
setIgnoreJTA(parent.getIgnoreJTA());
}
}
if (!hasIsLockGrantor()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasIsLockGrantor()) {
setLockGrantor(parent.isLockGrantor());
}
} else {
setLockGrantor(parent.isLockGrantor());
}
}
if (!hasConcurrencyLevel()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasConcurrencyLevel()) {
setConcurrencyLevel(parent.getConcurrencyLevel());
}
} else {
setConcurrencyLevel(parent.getConcurrencyLevel());
}
}
if (!hasConcurrencyChecksEnabled()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasConcurrencyChecksEnabled()) {
setConcurrencyChecksEnabled(parent.getConcurrencyChecksEnabled());
}
} else {
setConcurrencyChecksEnabled(parent.getConcurrencyChecksEnabled());
}
}
if (!hasEarlyAck()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasEarlyAck()) {
setEarlyAck(parent.getEarlyAck());
}
} else {
setEarlyAck(parent.getEarlyAck());
}
}
if (!this.hasEnableSubscriptionConflation()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasEnableSubscriptionConflation()) {
setEnableSubscriptionConflation(parent.getEnableSubscriptionConflation());
}
} else {
setEnableSubscriptionConflation(parent.getEnableSubscriptionConflation());
}
}
if (!hasPublisher()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasPublisher()) {
setPublisher(parent.getPublisher());
}
} else {
setPublisher(parent.getPublisher());
}
}
if (!hasEnableAsyncConflation()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasEnableAsyncConflation()) {
setEnableAsyncConflation(parent.getEnableAsyncConflation());
}
} else {
setEnableAsyncConflation(parent.getEnableAsyncConflation());
}
}
if (!hasMulticastEnabled()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasMulticastEnabled()) {
setMulticastEnabled(parent.getMulticastEnabled());
}
} else {
setMulticastEnabled(parent.getMulticastEnabled());
}
}
if (!hasDiskWriteAttributes()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasDiskWriteAttributes()) {
setDiskWriteAttributes(parent.getDiskWriteAttributes());
}
} else {
setDiskWriteAttributes(parent.getDiskWriteAttributes());
}
}
if (!hasDiskDirs()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasDiskDirs()) {
setDiskDirs(parent.getDiskDirs());
}
} else {
setDiskDirs(parent.getDiskDirs());
}
}
if (!hasIndexMaintenanceSynchronous()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasIndexMaintenanceSynchronous()) {
setIndexMaintenanceSynchronous(parent.getIndexMaintenanceSynchronous());
}
} else {
setIndexMaintenanceSynchronous(parent.getIndexMaintenanceSynchronous());
}
}
if (!hasPartitionAttributes()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasPartitionAttributes()) {
setPartitionAttributes(parent.getPartitionAttributes());
}
} else {
setPartitionAttributes(parent.getPartitionAttributes());
}
}
if (!hasSubscriptionAttributes()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasSubscriptionAttributes()) {
setSubscriptionAttributes(parent.getSubscriptionAttributes());
}
} else {
setSubscriptionAttributes(parent.getSubscriptionAttributes());
}
}
if (!hasDataPolicy()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasDataPolicy()) {
setDataPolicy(parent.getDataPolicy());
}
} else {
setDataPolicy(parent.getDataPolicy());
}
}
if (!hasEvictionAttributes()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasEvictionAttributes()) {
setEvictionAttributes(parent.getEvictionAttributes());
}
} else {
setEvictionAttributes(parent.getEvictionAttributes());
}
}
if (!hasPoolName()) {
setPoolName(parent.getPoolName());
}
if (!hasDiskStoreName()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasDiskStoreName()) {
setDiskStoreName(parent.getDiskStoreName());
}
} else {
setDiskStoreName(parent.getDiskStoreName());
}
}
if (!hasDiskSynchronous()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasDiskSynchronous()) {
setDiskSynchronous(parent.isDiskSynchronous());
}
} else {
setDiskSynchronous(parent.isDiskSynchronous());
}
}
if (!hasCompressor()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasCompressor()) {
setCompressor(parent.getCompressor());
}
} else {
setCompressor(parent.getCompressor());
}
}
if (!hasConcurrencyChecksEnabled()) {
if (parentIsUserSpecified) {
if (parentWithHas.hasConcurrencyChecksEnabled()) {
setConcurrencyChecksEnabled(parent.getConcurrencyChecksEnabled());
}
} else {
setConcurrencyChecksEnabled(parent.getConcurrencyChecksEnabled());
}
}
if (!hasMulticastEnabled()) {
// bug #38836 - inherit multicast setting
if (parentIsUserSpecified) {
if (parentWithHas.hasMulticastEnabled()) {
setMulticastEnabled(parent.getMulticastEnabled());
}
} else {
setMulticastEnabled(parent.getMulticastEnabled());
}
}
}
use of org.apache.geode.internal.cache.GemFireCacheImpl in project geode by apache.
the class ClientCacheFactoryJUnitTest method test001FindDefaultFromXML.
@Test
public void test001FindDefaultFromXML() throws Exception {
this.tmpFile = File.createTempFile("ClientCacheFactoryJUnitTest", ".xml");
this.tmpFile.deleteOnExit();
URL url = ClientCacheFactoryJUnitTest.class.getResource("ClientCacheFactoryJUnitTest_single_pool.xml");
;
FileUtils.copyFile(new File(url.getFile()), this.tmpFile);
this.cc = new ClientCacheFactory().set(CACHE_XML_FILE, this.tmpFile.getAbsolutePath()).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("my_pool_name", defPool.getName());
assertEquals(new ArrayList(), defPool.getLocators());
assertEquals(Collections.singletonList(new InetSocketAddress("localhost", CacheServer.DEFAULT_PORT)), defPool.getServers());
}
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());
}
}
Aggregations