@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()); }
@Test public void executeFunctionGivenARegionWithJdbcAsyncEventQueueRemovesTheQueueName() { String queueName = CreateMappingCommand.createAsyncEventQueueName(regionName); when(regionAttributes.getAsyncEventQueueIds()).thenReturn(Collections.singleton(queueName)); when(service.getMappingForRegion(eq(regionName))).thenReturn(mapping); function.executeFunction(context); verify(regionMutator, times(1)).removeAsyncEventQueueId(queueName); }
@Override public RegionAttributes beforeCreate(Region parent, String regionName, RegionAttributes attrs, InternalRegionArguments internalRegionArgs) { RegionAttributes updatedRA = attrs; String path = parent == null ? "/" + regionName : parent.getFullPath() + "/" + regionName; if (path.equals(this.regionPath) && this.beforeCreateInvoked.compareAndSet(false, true)) { LuceneServiceImpl.validateRegionAttributes(attrs); String aeqId = LuceneServiceImpl.getUniqueIndexName(this.indexName, this.regionPath); if (!attrs.getAsyncEventQueueIds().contains(aeqId)) { AttributesFactory af = new AttributesFactory(attrs); af.addAsyncEventQueueId(aeqId); updatedRA = af.create(); } // Add index creation profile internalRegionArgs.addCacheServiceProfile(new LuceneIndexCreationProfile(this.indexName, this.regionPath, this.fields, this.analyzer, this.fieldAnalyzers, serializer)); luceneIndex = this.service.beforeDataRegionCreated(this.indexName, this.regionPath, attrs, this.analyzer, this.fieldAnalyzers, aeqId, serializer, this.fields); // Add internal async event id internalRegionArgs.addInternalAsyncEventQueueId(aeqId); } return updatedRA; }
@Test public void beforeDataRegionCreatedShouldHaveSerializer() { String name = "indexName"; String regionPath = "regionName"; String[] fields = {"field1", "field2"}; String aeqId = LuceneServiceImpl.getUniqueIndexName(name, regionPath); InternalCache cache = Fakes.cache(); final Region region = Fakes.region(regionPath, cache); RegionAttributes attributes = region.getAttributes(); DataPolicy policy = attributes.getDataPolicy(); when(policy.withPartitioning()).thenReturn(true); EvictionAttributes evictionAttributes = mock(EvictionAttributes.class); when(attributes.getEvictionAttributes()).thenReturn(evictionAttributes); CopyOnWriteArraySet set = new CopyOnWriteArraySet(); set.add(aeqId); when(attributes.getAsyncEventQueueIds()).thenReturn(set); when(evictionAttributes.getAlgorithm()).thenReturn(EvictionAlgorithm.NONE); LuceneServiceImpl service = mock(LuceneServiceImpl.class); Analyzer analyzer = mock(Analyzer.class); LuceneSerializer serializer = mock(LuceneSerializer.class); InternalRegionArguments internalRegionArgs = mock(InternalRegionArguments.class); when(internalRegionArgs.addCacheServiceProfile(any())).thenReturn(internalRegionArgs); LuceneRegionListener listener = new LuceneRegionListener(service, cache, name, "/" + regionPath, fields, analyzer, null, serializer); listener.beforeCreate(null, regionPath, attributes, internalRegionArgs); verify(service).beforeDataRegionCreated(eq(name), eq("/" + regionPath), eq(attributes), eq(analyzer), any(), eq(aeqId), eq(serializer), any()); } }
asyncEventQueueIDs = ra.getAsyncEventQueueIds(); gatewaySenderIDs = ra.getGatewaySenderIds();
boolean offheap = regAttrs.getOffHeap(); Set<String> eventQueueIds = regAttrs.getAsyncEventQueueIds(); Set<String> gatewaySenderIds = regAttrs.getGatewaySenderIds();
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(); } } }
if ((!(attrs instanceof RegionAttributesCreation) || ((RegionAttributesCreation) attrs).hasAsyncEventListeners())) { Set<String> asyncEventQueueIds = new HashSet<String>(attrs.getAsyncEventQueueIds()); StringBuilder asyncEventQueueStringBuff = new StringBuilder(); if (asyncEventQueueIds.size() != 0) {
this.cacheListeners = new ArrayList(Arrays.asList(attrs.getCacheListeners())); this.gatewaySenderIds = new HashSet<String>(attrs.getGatewaySenderIds()); this.asyncEventQueueIds = new HashSet<String>(attrs.getAsyncEventQueueIds()); this.cacheLoader = attrs.getCacheLoader(); this.cacheWriter = attrs.getCacheWriter();
this.earlyAck = attrs.getEarlyAck(); this.gatewaySenderIds = attrs.getGatewaySenderIds(); this.asyncEventQueueIds = attrs.getAsyncEventQueueIds(); initializeVisibleAsyncEventQueueIds(internalRegionArgs); setAllGatewaySenderIds();
new CopyOnWriteArraySet<String>(regionAttributes.getGatewaySenderIds()); this.regionAttributes.asyncEventQueueIds = new CopyOnWriteArraySet<String>(regionAttributes.getAsyncEventQueueIds()); this.regionAttributes.isLockGrantor = regionAttributes.isLockGrantor(); // fix for bug 47067 if (regionAttributes instanceof UserSpecifiedRegionAttributes) {
this.isDiskSynchronous = attr.isDiskSynchronous(); this.gatewaySendersDescs = getDescs(attr.getGatewaySenderIds().toArray()); this.asyncEventQueueDescs = getDescs(attr.getAsyncEventQueueIds().toArray()); this.compressorDesc = getDesc(attr.getCompressor()); this.offHeap = attr.getOffHeap();
if (parentIsUserSpecified) { if (parentWithHas.hasAsyncEventListeners()) { initAsyncEventQueues(parent.getAsyncEventQueueIds()); initAsyncEventQueues(parent.getAsyncEventQueueIds());
mock(RegionAttributes.class, mockObjectIdentifier("MockRegionAttributes")); when(mockRegionAttributes.getAsyncEventQueueIds()).thenReturn(asyncEventQueueIds);
new CopyOnWriteArrayList<>(nullSafeSet(baseRegionAttributes.getAsyncEventQueueIds())); when(mockRegionAttributes.getAsyncEventQueueIds()) .thenAnswer(invocation -> asSet(asyncEventQueueIds.toArray(new String[asyncEventQueueIds.size()])));