forked from hazelcast/hazelcast
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix Ringbuffer test failures [5.0.z]
Fixes hazelcast#19696 ReliableTopicDestroyTest.whenDestroyedThenRingbufferRemoved Created a simpler reproducer RingbufferDestroyTest.whenDestroyAfterAdd_thenRingbufferRemoved The cause was recreation of the RingbufferContainer in ReadOneOperation.getWaitKey This also addresses review comment from hazelcast#19630. Fixes hazelcast#16469 RingbufferAddAllReadManyStressTest.whenShortTTLAndBigBuffer The stress test is incorrect, the ReadManyOperation doesn't throw the StaleSequenceException when head is stale and the items are just missing in the result. This was introduced in hazelcast#16303. Also fixed HashMap->ConcurrentHashMap in RingbufferService. This Map is modified from operation thread when RingbufferContainer is created and also from destroyContainer, which may run directly on the user's thread when the ringbuffer is local on the member. Backport of hazelcast#19788
- Loading branch information
1 parent
aafdf51
commit fc671fb
Showing
8 changed files
with
190 additions
and
21 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
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
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
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
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
97 changes: 97 additions & 0 deletions
97
hazelcast/src/test/java/com/hazelcast/ringbuffer/impl/RingbufferDestroyTest.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,97 @@ | ||
/* | ||
* Copyright (c) 2008-2021, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.hazelcast.ringbuffer.impl; | ||
|
||
import com.hazelcast.config.Config; | ||
import com.hazelcast.config.RingbufferConfig; | ||
import com.hazelcast.core.HazelcastInstance; | ||
import com.hazelcast.internal.services.ObjectNamespace; | ||
import com.hazelcast.ringbuffer.Ringbuffer; | ||
import com.hazelcast.test.AssertTask; | ||
import com.hazelcast.test.HazelcastTestSupport; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static com.hazelcast.test.Accessors.getNodeEngineImpl; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
public class RingbufferDestroyTest extends HazelcastTestSupport { | ||
|
||
public static final String NAME = "ringbuffer-foo"; | ||
|
||
private static HazelcastInstance[] instances; | ||
private Ringbuffer<String> ringbuffer; | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
Config config = smallInstanceConfig(); | ||
config.addRingBufferConfig(new RingbufferConfig(NAME).setCapacity(10)); | ||
instances = createHazelcastInstances(config, 2); | ||
|
||
ringbuffer = instances[0].getRingbuffer(NAME); | ||
} | ||
|
||
@Test | ||
public void whenDestroyAfterAdd_thenRingbufferRemoved() { | ||
ringbuffer.add("1"); | ||
ringbuffer.destroy(); | ||
|
||
assertTrueEventually(new AssertNoRingbufferContainerTask(), 10); | ||
} | ||
|
||
@Test | ||
public void whenReadOneAfterDestroy_thenMustNotRecreateRingbuffer() { | ||
ringbuffer.add("1"); | ||
ringbuffer.destroy(); | ||
|
||
spawn(() -> ringbuffer.readOne(0)); | ||
|
||
sleepMillis(100); | ||
|
||
assertTrueEventually(new AssertNoRingbufferContainerTask(), 10); | ||
} | ||
|
||
@Test | ||
public void whenReadManyAfterDestroy_thenMustNotRecreateRingbuffer() { | ||
ringbuffer.add("1"); | ||
ringbuffer.destroy(); | ||
|
||
spawn(() -> ringbuffer.readManyAsync(0, 1, 1, null)); | ||
|
||
sleepMillis(100); | ||
|
||
assertTrueEventually(new AssertNoRingbufferContainerTask(), 10); | ||
} | ||
|
||
private static class AssertNoRingbufferContainerTask implements AssertTask { | ||
@Override | ||
public void run() throws Exception { | ||
for (HazelcastInstance instance : instances) { | ||
final RingbufferService ringbufferService | ||
= getNodeEngineImpl(instance).getService(RingbufferService.SERVICE_NAME); | ||
|
||
final Map<ObjectNamespace, RingbufferContainer> partitionContainers = | ||
ringbufferService.getContainers().get(ringbufferService.getRingbufferPartitionId(NAME)); | ||
assertNotNull(partitionContainers); | ||
assertFalse(partitionContainers.containsKey(RingbufferService.getRingbufferNamespace(NAME))); | ||
} | ||
} | ||
} | ||
} |
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
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