use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DurableClientSimpleDUnitTest method verifyDurableCqs.
public static void verifyDurableCqs(final List<String> durableCqNames, final String registeredCqName) {
// Verify the number of durable CQ names is one, and it matches the registered name
assertEquals(1, durableCqNames.size());
String returnedCqName = durableCqNames.get(0);
assertEquals(registeredCqName, returnedCqName);
// Get client's primary server
PoolImpl pool = CacheServerTestUtil.getPool();
ServerLocation primaryServerLocation = pool.getPrimary();
// Verify the primary server was used and no other server was used
Map<ServerLocation, ConnectionStats> statistics = pool.getEndpointManager().getAllStats();
for (Map.Entry<ServerLocation, ConnectionStats> entry : statistics.entrySet()) {
int expectedGetDurableCqInvocations = entry.getKey().equals(primaryServerLocation) ? 1 : 0;
assertEquals(expectedGetDurableCqInvocations, entry.getValue().getGetDurableCqs());
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DurableClientSimpleDUnitTest method testReadyForEventsNotCalledImplicitlyWithCacheXML.
/**
* This test method is disabled because it is failing periodically and causing cruise control
* failures See bug #47060 (test seems to be enabled now!)
*/
@Test
public void testReadyForEventsNotCalledImplicitlyWithCacheXML() {
try {
setPeriodicACKObserver(durableClientVM);
final String cqName = "cqTest";
// Start a server
int serverPort = (Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerFromXml(DurableClientTestCase.class.getResource("durablecq-server-cache.xml")));
// Start a durable client that is not kept alive on the server when it
// stops normally
final String durableClientId = getName() + "_client";
// create client cache from xml
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXml(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.FALSE));
// verify that readyForEvents has not yet been called on all the client's pools
this.durableClientVM.invoke(new CacheSerializableRunnable("check readyForEvents not called") {
@Override
public void run2() throws CacheException {
for (Pool p : PoolManager.getAll().values()) {
assertEquals(false, ((PoolImpl) p).getReadyForEventsCalled());
}
}
});
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@Override
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
registerDurableCq(cqName);
// Verify durable client on server1
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable
assertTrue(proxy.isDurable());
assertEquals(durableClientId, proxy.getDurableId());
}
});
// Start normal publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, false), regionName));
// Publish some entries
final int numberOfEntries = 10;
publishEntries(numberOfEntries);
// Verify the durable client received the updates
this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Get the listener and wait for the appropriate number of events
QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
CqQuery cqQuery = queryService.getCq(cqName);
CacheServerTestUtil.ControlCqListener cqlistener = (CacheServerTestUtil.ControlCqListener) cqQuery.getCqAttributes().getCqListener();
cqlistener.waitWhileNotEnoughEvents(30000, numberOfEntries);
assertEquals(numberOfEntries, cqlistener.events.size());
}
});
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
fail("interrupted", e);
}
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache(new Boolean(true)));
// Verify the durable client still exists on the server
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
}
});
// Publish some more entries
publishEntries(numberOfEntries);
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Re-start the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXml(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.FALSE));
// Durable client registers durable cq on server
this.durableClientVM.invoke(new CacheSerializableRunnable("Register cq") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Create CQ Attributes.
CqAttributesFactory cqAf = new CqAttributesFactory();
// Initialize and set CqListener.
CqListener[] cqListeners = { new CacheServerTestUtil.ControlCqListener() };
cqAf.initCqListeners(cqListeners);
CqAttributes cqa = cqAf.create();
// Create cq's
// Get the query service for the Pool
QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
try {
CqQuery query = queryService.newCq(cqName, "Select * from /" + regionName, cqa, true);
query.execute();
} catch (CqExistsException e) {
fail("Failed due to ", e);
} catch (CqException e) {
fail("Failed due to ", e);
} catch (RegionNotFoundException e) {
fail("Could not find specified region:" + regionName + ":", e);
}
}
});
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@Override
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
// Verify durable client on server
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable and its properties are correct
assertTrue(proxy.isDurable());
assertEquals(durableClientId, proxy.getDurableId());
}
});
// Verify the durable client received the updates held for it on the server
this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
QueryService queryService = CacheServerTestUtil.getPool().getQueryService();
CqQuery cqQuery = queryService.getCq(cqName);
CacheServerTestUtil.ControlCqListener cqlistener = (CacheServerTestUtil.ControlCqListener) cqQuery.getCqAttributes().getCqListener();
cqlistener.waitWhileNotEnoughEvents(30000, numberOfEntries);
assertEquals(numberOfEntries, cqlistener.events.size());
}
});
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
} finally {
unsetPeriodicACKObserver(durableClientVM);
}
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DurableClientSimpleDUnitTest method testReadyForEventsNotCalledImplicitlyForRegisterInterestWithCacheXML.
@Test
public void testReadyForEventsNotCalledImplicitlyForRegisterInterestWithCacheXML() {
final String cqName = "cqTest";
regionName = "testReadyForEventsNotCalledImplicitlyWithCacheXML_region";
// Start a server
int serverPort = (Integer) this.server1VM.invoke(() -> CacheServerTestUtil.createCacheServerFromXmlN(DurableClientTestCase.class.getResource("durablecq-server-cache.xml")));
// Start a durable client that is not kept alive on the server when it
// stops normally
final String durableClientId = getName() + "_client";
// create client cache from xml
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXmlN(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.TRUE));
// verify that readyForEvents has not yet been called on all the client's pools
this.durableClientVM.invoke(new CacheSerializableRunnable("check readyForEvents not called") {
@Override
public void run2() throws CacheException {
for (Pool p : PoolManager.getAll().values()) {
assertEquals(false, ((PoolImpl) p).getReadyForEventsCalled());
}
}
});
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@Override
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
// Durable client registers durable cq on server
this.durableClientVM.invoke(new CacheSerializableRunnable("Register Interest") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Register interest in all keys
region.registerInterestRegex(".*", InterestResultPolicy.KEYS_VALUES, true);
}
});
// Verify durable client on server1
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable
assertTrue(proxy.isDurable());
assertEquals(durableClientId, proxy.getDurableId());
}
});
// Start normal publisher client
this.publisherClientVM.invoke(() -> CacheServerTestUtil.createCacheClient(getClientPool(getServerHostName(publisherClientVM.getHost()), serverPort, false), regionName));
// Publish some entries
final int numberOfEntries = 10;
publishEntries(numberOfEntries);
// Verify the durable client received the updates
this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Get the listener and wait for the appropriate number of events
CacheServerTestUtil.ControlListener listener = (CacheServerTestUtil.ControlListener) region.getAttributes().getCacheListeners()[0];
listener.waitWhileNotEnoughEvents(30000, numberOfEntries);
assertEquals(numberOfEntries, listener.events.size());
}
});
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
fail("interrupted", e);
}
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache(new Boolean(true)));
// Verify the durable client still exists on the server
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
}
});
// Publish some more entries
this.publisherClientVM.invoke(new CacheSerializableRunnable("Publish additional updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Publish some entries
for (int i = 0; i < numberOfEntries; i++) {
String keyAndValue = String.valueOf(i);
region.put(keyAndValue, keyAndValue + "lkj");
}
}
});
this.publisherClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Re-start the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.createCacheClientFromXmlN(DurableClientTestCase.class.getResource("durablecq-client-cache.xml"), "client", durableClientId, 45, Boolean.TRUE));
// Durable client registers durable cq on server
this.durableClientVM.invoke(new CacheSerializableRunnable("Register interest") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Register interest in all keys
region.registerInterestRegex(".*", InterestResultPolicy.KEYS_VALUES, true);
}
});
// Send clientReady message
this.durableClientVM.invoke(new CacheSerializableRunnable("Send clientReady") {
@Override
public void run2() throws CacheException {
CacheServerTestUtil.getCache().readyForEvents();
}
});
// Verify durable client on server
this.server1VM.invoke(new CacheSerializableRunnable("Verify durable client") {
@Override
public void run2() throws CacheException {
// Find the proxy
checkNumberOfClientProxies(1);
CacheClientProxy proxy = getClientProxy();
assertNotNull(proxy);
// Verify that it is durable and its properties are correct
assertTrue(proxy.isDurable());
assertEquals(durableClientId, proxy.getDurableId());
}
});
// Verify the durable client received the updates held for it on the server
this.durableClientVM.invoke(new CacheSerializableRunnable("Verify updates") {
@Override
public void run2() throws CacheException {
// Get the region
Region region = CacheServerTestUtil.getCache().getRegion(regionName);
assertNotNull(region);
// Get the listener and wait for the appropriate number of events
CacheServerTestUtil.ControlListener listener = (CacheServerTestUtil.ControlListener) region.getAttributes().getCacheListeners()[0];
listener.waitWhileNotEnoughEvents(30000, numberOfEntries);
assertEquals(numberOfEntries, listener.events.size());
}
});
// Stop the durable client
this.durableClientVM.invoke(() -> CacheServerTestUtil.closeCache());
// Stop the server
this.server1VM.invoke(() -> CacheServerTestUtil.closeCache());
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class DeltaToRegionRelationCQRegistrationDUnitTest method createClientCache2.
/*
* create client cache and return's primary server location object (primary)
*/
public static Integer createClientCache2(String host1, String host2, Integer port1, Integer port2) throws Exception {
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new DeltaToRegionRelationCQRegistrationDUnitTest().createCache(props);
PoolImpl p = (PoolImpl) PoolManager.createFactory().addServer(host1, port1.intValue()).addServer(host2, port2.intValue()).setThreadLocalConnections(true).setMinConnections(3).setSubscriptionEnabled(true).setSubscriptionRedundancy(0).setReadTimeout(10000).setSocketBufferSize(32768).create("DeltaToRegionRelationCQRegistrationTestPool");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.EMPTY);
factory.setPoolName(p.getName());
// region with empty data policy
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME1, attrs);
factory.setDataPolicy(DataPolicy.NORMAL);
attrs = factory.create();
// region with non empty data policy
cache.createRegion(REGION_NAME2, attrs);
return new Integer(p.getPrimaryPort());
}
use of org.apache.geode.cache.client.internal.PoolImpl in project geode by apache.
the class AbstractRegion method setAttributes.
private void setAttributes(RegionAttributes attrs, String regionName, InternalRegionArguments internalRegionArgs) {
// do this one first
this.dataPolicy = attrs.getDataPolicy();
this.scope = attrs.getScope();
this.offHeap = attrs.getOffHeap();
// fix bug #52033 by invoking setOffHeap now (localMaxMemory may now be the temporary
// placeholder for off-heap until DistributedSystem is created
// found non-null PartitionAttributes and offHeap is true so let's setOffHeap on PA now
PartitionAttributes<?, ?> partitionAttributes = attrs.getPartitionAttributes();
if (this.offHeap && partitionAttributes != null) {
PartitionAttributesImpl impl = (PartitionAttributesImpl) partitionAttributes;
impl.setOffHeap(true);
}
this.evictionAttributes = new EvictionAttributesImpl((EvictionAttributesImpl) attrs.getEvictionAttributes());
if (attrs.getPartitionAttributes() != null && this.evictionAttributes != null && this.evictionAttributes.getAlgorithm().isLRUMemory() && attrs.getPartitionAttributes().getLocalMaxMemory() != 0 && this.evictionAttributes.getMaximum() != attrs.getPartitionAttributes().getLocalMaxMemory()) {
logger.warn(LocalizedMessage.create(LocalizedStrings.Mem_LRU_Eviction_Attribute_Reset, new Object[] { regionName, this.evictionAttributes.getMaximum(), attrs.getPartitionAttributes().getLocalMaxMemory() }));
this.evictionAttributes.setMaximum(attrs.getPartitionAttributes().getLocalMaxMemory());
}
if (this.evictionAttributes != null && !this.evictionAttributes.getAlgorithm().isNone()) {
setEvictionController(this.evictionAttributes.createEvictionController(this, attrs.getOffHeap()));
}
storeCacheListenersField(attrs.getCacheListeners());
assignCacheLoader(attrs.getCacheLoader());
assignCacheWriter(attrs.getCacheWriter());
this.regionTimeToLive = attrs.getRegionTimeToLive().getTimeout();
this.regionTimeToLiveExpirationAction = attrs.getRegionTimeToLive().getAction();
setRegionTimeToLiveAtts();
this.regionIdleTimeout = attrs.getRegionIdleTimeout().getTimeout();
this.regionIdleTimeoutExpirationAction = attrs.getRegionIdleTimeout().getAction();
setRegionIdleTimeoutAttributes();
this.entryTimeToLive = attrs.getEntryTimeToLive().getTimeout();
this.entryTimeToLiveExpirationAction = attrs.getEntryTimeToLive().getAction();
setEntryTimeToLiveAttributes();
this.customEntryTimeToLive = attrs.getCustomEntryTimeToLive();
this.entryIdleTimeout = attrs.getEntryIdleTimeout().getTimeout();
this.entryIdleTimeoutExpirationAction = attrs.getEntryIdleTimeout().getAction();
setEntryIdleTimeoutAttributes();
this.customEntryIdleTimeout = attrs.getCustomEntryIdleTimeout();
updateEntryExpiryPossible();
this.statisticsEnabled = attrs.getStatisticsEnabled();
this.ignoreJTA = attrs.getIgnoreJTA();
this.isLockGrantor = attrs.isLockGrantor();
this.keyConstraint = attrs.getKeyConstraint();
this.valueConstraint = attrs.getValueConstraint();
this.initialCapacity = attrs.getInitialCapacity();
this.loadFactor = attrs.getLoadFactor();
this.concurrencyLevel = attrs.getConcurrencyLevel();
this.concurrencyChecksEnabled = attrs.getConcurrencyChecksEnabled() && supportsConcurrencyChecks();
this.earlyAck = attrs.getEarlyAck();
this.gatewaySenderIds = attrs.getGatewaySenderIds();
this.asyncEventQueueIds = attrs.getAsyncEventQueueIds();
initializeVisibleAsyncEventQueueIds(internalRegionArgs);
setAllGatewaySenderIds();
this.enableSubscriptionConflation = attrs.getEnableSubscriptionConflation();
this.publisher = attrs.getPublisher();
this.enableAsyncConflation = attrs.getEnableAsyncConflation();
this.indexMaintenanceSynchronous = attrs.getIndexMaintenanceSynchronous();
this.mcastEnabled = attrs.getMulticastEnabled();
this.partitionAttributes = attrs.getPartitionAttributes();
this.membershipAttributes = attrs.getMembershipAttributes();
this.subscriptionAttributes = attrs.getSubscriptionAttributes();
this.cloningEnable = attrs.getCloningEnabled();
this.poolName = attrs.getPoolName();
if (this.poolName != null) {
PoolImpl cp = getPool();
if (cp == null) {
throw new IllegalStateException(LocalizedStrings.AbstractRegion_THE_CONNECTION_POOL_0_HAS_NOT_BEEN_CREATED.toLocalizedString(this.poolName));
}
cp.attach();
if (cp.getMultiuserAuthentication() && !this.dataPolicy.isEmpty()) {
throw new IllegalStateException("Region must have empty data-policy " + "when multiuser-authentication is true.");
}
}
this.diskStoreName = attrs.getDiskStoreName();
this.isDiskSynchronous = attrs.isDiskSynchronous();
if (this.diskStoreName == null) {
this.diskWriteAttributes = attrs.getDiskWriteAttributes();
// fixes bug 41313
this.isDiskSynchronous = this.diskWriteAttributes.isSynchronous();
this.diskDirs = attrs.getDiskDirs();
this.diskSizes = attrs.getDiskDirSizes();
}
this.compressor = attrs.getCompressor();
// enable concurrency checks for persistent regions
if (!attrs.getConcurrencyChecksEnabled() && attrs.getDataPolicy().withPersistence() && supportsConcurrencyChecks()) {
throw new IllegalStateException(LocalizedStrings.AttributesFactory_CONCURRENCY_CHECKS_MUST_BE_ENABLED.toLocalizedString());
}
}
Aggregations