@Override public void run() { checkCCRegionTombstoneCount("after create+destroy in other vm ", numEntries); afterCreates = 0; AttributesMutator<Object, Object> m = attributesMutatorFor(CCRegion); m.addCacheListener(new CacheListenerAdapter<Object, Object>() { @Override public void afterCreate(EntryEvent<Object, Object> event) { afterCreates++; } }); } });
mutator.initCacheListeners(attrs.getCacheListeners()); mutator.setCacheLoader(attrs.getCacheLoader()); mutator.setCacheWriter(attrs.getCacheWriter()); mutator.setEntryIdleTimeout(attrs.getEntryIdleTimeout()); mutator.setCustomEntryIdleTimeout(attrs.getCustomEntryIdleTimeout()); mutator.setEntryTimeToLive(attrs.getEntryTimeToLive()); mutator.setCustomEntryTimeToLive(attrs.getCustomEntryTimeToLive()); mutator.setRegionIdleTimeout(attrs.getEntryIdleTimeout()); mutator.setRegionTimeToLive(attrs.getRegionTimeToLive()); mutator.setCloningEnabled(attrs.getCloningEnabled());
@Test public void updateWithGatewaySenders() { regionAttributes.setGatewaySenderIds("2,3"); when(region.getGatewaySenderIds()).thenReturn(new HashSet<>(Arrays.asList("1", "2"))); function.alterRegion(cache, config); verify(mutator).removeGatewaySenderId("1"); verify(mutator, times(0)).removeGatewaySenderId("2"); verify(mutator).addGatewaySenderId("3"); // asyncEventQueue is left intact verify(mutator, times(0)).addAsyncEventQueueId(any()); verify(mutator, times(0)).removeAsyncEventQueueId(any()); }
void installCacheListenerAndWriter() { AttributesMutator<String, String> mutator = this.region.getAttributesMutator(); mutator.addCacheListener(new CacheListenerAdapter<String, String>() { @Override public void close() { mutator.setCacheWriter(new CacheWriter<String, String>() { @Override public void close() {
/** * Change the existing region to have * the JdbcLoader as its cache-loader * and the given async-event-queue as one of its queues. */ private void alterRegion(Region<?, ?> region, String queueName, boolean synchronous) { region.getAttributesMutator().setCacheLoader(new JdbcLoader()); if (synchronous) { region.getAttributesMutator().setCacheWriter(new JdbcWriter()); } else { region.getAttributesMutator().addAsyncEventQueueId(queueName); } }
mutator.setCloningEnabled(regionAttributes.isCloningEnabled()); if (logger.isDebugEnabled()) { logger.debug("Region successfully altered - cloning"); mutator.getEvictionAttributesMutator().setMaximum(Integer .parseInt(regionAttributes.getEvictionAttributes().getLruEntryCount().getMaximum())); if (logger.isDebugEnabled()) { region.getEntryIdleTimeout(), p -> mutator.setEntryIdleTimeout(p), p -> mutator.setCustomEntryIdleTimeout(p)); updateExpirationAttributes(cache, regionAttributes.getEntryTimeToLive(), region.getEntryTimeToLive(), p -> mutator.setEntryTimeToLive(p), p -> mutator.setCustomEntryTimeToLive(p)); updateExpirationAttributes(cache, regionAttributes.getRegionIdleTime(), region.getRegionIdleTimeout(), p -> mutator.setRegionIdleTimeout(p), null); updateExpirationAttributes(cache, regionAttributes.getRegionTimeToLive(), region.getRegionTimeToLive(), p -> mutator.setRegionTimeToLive(p), null); for (String gatewaySenderId : oldGatewaySenderIds) { if (!newGatewaySenderIds.contains(gatewaySenderId)) { mutator.removeGatewaySenderId(gatewaySenderId); mutator.addGatewaySenderId(gatewaySenderId); for (String asyncEventQueueId : oldAsyncEventQueueIds) { if (!newAsyncEventQueueIds.contains(asyncEventQueueId)) { mutator.removeAsyncEventQueueId(asyncEventQueueId); mutator.addAsyncEventQueueId(asyncEventQueueId);
@Test public void updateWithNoCacheWriter() { regionAttributes.setCacheWriter(DeclarableType.EMPTY); function.alterRegion(cache, config); verify(mutator).setCacheWriter(null); verify(mutator, times(0)).setCacheLoader(any()); } }
private void cleanupRegionAndQueue(Cache cache, String regionName) { String queueName = CreateMappingCommand.createAsyncEventQueueName(regionName); Region<?, ?> region = cache.getRegion(regionName); if (region != null) { CacheLoader<?, ?> loader = region.getAttributes().getCacheLoader(); if (loader instanceof JdbcLoader) { region.getAttributesMutator().setCacheLoader(null); } CacheWriter<?, ?> writer = region.getAttributes().getCacheWriter(); if (writer instanceof JdbcWriter) { region.getAttributesMutator().setCacheWriter(null); } Set<String> queueIds = region.getAttributes().getAsyncEventQueueIds(); if (queueIds.contains(queueName)) { region.getAttributesMutator().removeAsyncEventQueueId(queueName); } } InternalAsyncEventQueue queue = (InternalAsyncEventQueue) cache.getAsyncEventQueue(queueName); if (queue != null) { queue.stop(); queue.destroy(); } } }
@Override public void visit(Integer bucketId, Region r) { AttributesMutator mut = r.getAttributesMutator(); if (logger.isDebugEnabled()) { logger.debug("setting new cache loader in bucket region: {}", newLoader); } mut.setCacheLoader(newLoader); } });
@Test public void updateWithEmptyCacheListeners() { // suppose region has on listener, and we want to delete that one CacheListener oldOne = mock(CacheListener.class); when(region.getCacheListeners()).thenReturn(new CacheListener[] {oldOne}); regionAttributes.getCacheListeners().add(DeclarableType.EMPTY); function.alterRegion(cache, config); verify(mutator).removeCacheListener(oldOne); verify(mutator, times(0)).addCacheListener(any()); }
@Override public void run2() throws CacheException { Region<Object, Object> region = createRegion(name); setWriter(new TestCacheWriter<Object, Object>() {}); region.getAttributesMutator().setCacheWriter(writer()); } };
@Test public void updateWithCustomExpiry() { RegionAttributesType.ExpirationAttributesType expiration = new RegionAttributesType.ExpirationAttributesType(); regionAttributes.setEntryIdleTime(expiration); DeclarableType mockExpiry = mock(DeclarableType.class); when(mockExpiry.getClassName()).thenReturn(MyCustomExpiry.class.getName()); expiration.setCustomExpiry(mockExpiry); function.alterRegion(cache, config); verify(mutator, times(0)).setEntryIdleTimeout(any()); verify(mutator).setCustomEntryIdleTimeout(notNull()); }
@Test public void executeFunctionGivenARegionWithNonJdbcAsyncEventQueueDoesNotRemoveTheQueueName() { when(regionAttributes.getAsyncEventQueueIds()) .thenReturn(Collections.singleton("nonJdbcQueue")); when(service.getMappingForRegion(eq(regionName))).thenReturn(mapping); function.executeFunction(context); verify(regionMutator, never()).removeAsyncEventQueueId(any()); }
@Before public void setUp() throws Exception { function = spy(RegionAlterFunction.class); config = new RegionConfig(); regionAttributes = new RegionAttributesType(); config.setRegionAttributes(regionAttributes); internalCache = mock(InternalCache.class); cache = mock(InternalCacheForClientAccess.class); mutator = mock(AttributesMutator.class); evictionMutator = mock(EvictionAttributesMutator.class); when(mutator.getEvictionAttributesMutator()).thenReturn(evictionMutator); region = mock(AbstractRegion.class); context = mock(FunctionContext.class); when(context.getCache()).thenReturn(internalCache); when(internalCache.getCacheForProcessingClientRequests()).thenReturn(cache); when(context.getArguments()).thenReturn(config); when(context.getMemberName()).thenReturn("member"); when(cache.getRegion(any())).thenReturn(region); when(region.getAttributesMutator()).thenReturn(mutator); }
@Test public void executeWithSynchronousNeverAltersRegionAsyncEventQueue() throws Exception { setupSynchronous(); function.executeFunction(context); AttributesMutator mutator = region.getAttributesMutator(); verify(mutator, never()).addAsyncEventQueueId(any()); }
@Override public void close() { instance.processors.remove(windowId); region.getAttributesMutator().removeCacheListener(crash); permits.release(MAX_PERMITS); }
/** * Changes the idleTimeout expiration attributes for values in the region. * * @param idleTimeout the idleTimeout expiration attributes for entries * @return the previous value of entry idleTimeout * @throws IllegalArgumentException if idleTimeout is null or if the ExpirationAction is * LOCAL_DESTROY and the region is {@link DataPolicy#withReplication replicated} or if the * the ExpirationAction is LOCAL_INVALIDATE and the region is * {@link DataPolicy#withReplication replicated} * @see AttributesFactory#setStatisticsEnabled * @throws IllegalStateException if statistics are disabled for this region. */ @Override public ExpirationAttributes setEntryIdleTimeout(ExpirationAttributes idleTimeout) { ExpirationAttributes attr = super.setEntryIdleTimeout(idleTimeout); /* * All buckets must be created to make this change, otherwise it is possible for * updatePRConfig(...) to make changes that cause bucket creation to live lock */ PartitionRegionHelper.assignBucketsToPartitions(this); // Set to Bucket regions as well dataStore.lockBucketCreationAndVisit( (bucketId, r) -> r.getAttributesMutator().setEntryIdleTimeout(idleTimeout)); updatePRConfig(getPRConfigWithLatestExpirationAttributes(), false); return attr; }
/** * Changes the CustomExpiry for idleTimeout for values in the region * * @param custom the new CustomExpiry * @return the old CustomExpiry */ @Override public CustomExpiry setCustomEntryIdleTimeout(CustomExpiry custom) { CustomExpiry expiry = super.setCustomEntryIdleTimeout(custom); // Set to Bucket regions as well dataStore.lockBucketCreationAndVisit( (bucketId, r) -> r.getAttributesMutator().setCustomEntryIdleTimeout(custom)); return expiry; }
when(mockAttributesMutator.getEvictionAttributesMutator()).thenReturn(mockEvictionAttributesMutator); when(mockAttributesMutator.getRegion()).thenReturn(mockRegion); .when(mockAttributesMutator).addAsyncEventQueueId(anyString()); .when(mockAttributesMutator).addCacheListener(any(CacheListener.class)); when(mockAttributesMutator).addGatewaySenderId(anyString()); when(mockAttributesMutator.getCloningEnabled()).thenAnswer(newGetter(cloningEnabled::get)); }).when(mockAttributesMutator).initCacheListeners(any(CacheListener[].class)); .when(mockAttributesMutator).removeAsyncEventQueueId(anyString()); .when(mockAttributesMutator).removeCacheListener(any(CacheListener.class)); .when(mockAttributesMutator).removeGatewaySenderId(anyString()); .when(mockAttributesMutator).setCacheLoader(any(CacheLoader.class)); .when(mockAttributesMutator).setCacheWriter(any(CacheWriter.class)); .when(mockAttributesMutator).setCloningEnabled(anyBoolean()); .when(mockAttributesMutator).setCustomEntryIdleTimeout(any(CustomExpiry.class)); .when(mockAttributesMutator).setCustomEntryTimeToLive(any(CustomExpiry.class));
@Test public void updateWithCacheWriter() { DeclarableType newCacheWriterDeclarable = mock(DeclarableType.class); when(newCacheWriterDeclarable.getClassName()).thenReturn(MyCacheWriter.class.getName()); regionAttributes.setCacheWriter(newCacheWriterDeclarable); function.alterRegion(cache, config); verify(mutator).setCacheWriter(notNull()); verify(mutator, times(0)).setCacheLoader(any()); }