-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 36033341 - [36028299->23.09.2] PagedTopic EnsureChannelCountTask …
…may attempt to modify read-only XML (merge ce/main -> ce/23.09 104795) [git-p4: depot-paths = "//dev/coherence-ce/release/coherence-ce-v23.09/": change = 104796]
- Loading branch information
1 parent
9d05775
commit 3d15e6a
Showing
2 changed files
with
111 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
prj/test/functional/topics/src/main/java/topics/EnsureChannelCountTaskTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright (c) 2000, 2023, Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Universal Permissive License v 1.0 as shown at | ||
* https://oss.oracle.com/licenses/upl. | ||
*/ | ||
|
||
package topics; | ||
|
||
import com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.PartitionedCache; | ||
import com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.partitionedCache.PagedTopic; | ||
import com.tangosol.coherence.component.util.daemon.queueProcessor.service.grid.partitionedService.partitionedCache.PagedTopic.EnsureChannelCountTask; | ||
|
||
import com.tangosol.internal.net.topic.impl.paged.PagedTopicCaches; | ||
import com.tangosol.run.xml.SimpleElement; | ||
import com.tangosol.run.xml.XmlElement; | ||
import org.junit.Test; | ||
|
||
import java.util.concurrent.locks.ReentrantLock; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class EnsureChannelCountTaskTest | ||
{ | ||
@Test | ||
public void shouldSetChannelCountIntoConfigMap() | ||
{ | ||
String sTopicName = "test-topic"; | ||
String sCacheName = PagedTopicCaches.Names.CONTENT.cacheNameForTopicName(sTopicName); | ||
ReentrantLock lock = new ReentrantLock(); | ||
XmlElement xmlCache = new SimpleElement(); | ||
EnsureChannelCountTask task = new EnsureChannelCountTask(); | ||
|
||
task.setChannelCount(29); | ||
task.setRequiredChannelCount(29); | ||
task.setTopicName(sTopicName); | ||
|
||
EnsureChannelCountTask stub = spy(task); | ||
|
||
PartitionedCache.ServiceConfig.Map configMap = mock(PartitionedCache.ServiceConfig.Map.class); | ||
PagedTopic service = mock(PagedTopic.class); | ||
|
||
when(stub.getService()).thenReturn(service); | ||
|
||
when(service.getChannelCountFromConfigMap(sTopicName)).thenReturn(17); | ||
when(service.getTopicStoreLock()).thenReturn(lock); | ||
when(service.isSuspendedFully()).thenReturn(true); | ||
when(service.getServiceConfigMap()).thenReturn(configMap); | ||
|
||
when(configMap.get(sCacheName)).thenReturn(xmlCache); | ||
|
||
stub.run(); | ||
|
||
assertThat(xmlCache.getSafeAttribute("channels").getInt(), is(29)); | ||
} | ||
|
||
@Test | ||
public void shouldUpdateChannelCountIntoConfigMap() | ||
{ | ||
String sTopicName = "test-topic"; | ||
String sCacheName = PagedTopicCaches.Names.CONTENT.cacheNameForTopicName(sTopicName); | ||
ReentrantLock lock = new ReentrantLock(); | ||
XmlElement xmlCache = new SimpleElement(); | ||
EnsureChannelCountTask task = new EnsureChannelCountTask(); | ||
|
||
xmlCache.addElement("channels").setInt(17); | ||
|
||
task.setChannelCount(29); | ||
task.setRequiredChannelCount(29); | ||
task.setTopicName(sTopicName); | ||
|
||
EnsureChannelCountTask stub = spy(task); | ||
|
||
PartitionedCache.ServiceConfig.Map configMap = mock(PartitionedCache.ServiceConfig.Map.class); | ||
PagedTopic service = mock(PagedTopic.class); | ||
|
||
when(stub.getService()).thenReturn(service); | ||
|
||
when(service.getChannelCountFromConfigMap(sTopicName)).thenReturn(17); | ||
when(service.getTopicStoreLock()).thenReturn(lock); | ||
when(service.isSuspendedFully()).thenReturn(true); | ||
when(service.getServiceConfigMap()).thenReturn(configMap); | ||
|
||
when(configMap.get(sCacheName)).thenReturn(xmlCache); | ||
|
||
stub.run(); | ||
|
||
assertThat(xmlCache.getSafeAttribute("channels").getInt(), is(29)); | ||
} | ||
} |