Skip to content

Commit

Permalink
Test case demoing version compatibility issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zyulyaev committed Oct 19, 2024
1 parent 3073a51 commit 34586a2
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright 2014-2024 Real Logic Limited.
*
* 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
*
* https://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 io.aeron.cluster;

import io.aeron.test.EventLogExtension;
import io.aeron.test.InterruptAfter;
import io.aeron.test.InterruptingTestCallback;
import io.aeron.test.SystemTestWatcher;
import io.aeron.test.cluster.TestCluster;
import org.agrona.SemanticVersion;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;

import static io.aeron.test.cluster.TestCluster.aCluster;

@ExtendWith({ EventLogExtension.class, InterruptingTestCallback.class })
class MultiNodeVersionValidationTest
{
@RegisterExtension
final SystemTestWatcher systemTestWatcher = new SystemTestWatcher();

@Test
@InterruptAfter(20)
void shouldSuccessfullyStartWithConfiguredMajorVersion()
{
final int appointedLeaderIndex = 1;

final TestCluster cluster = aCluster()
.withStaticNodes(3)
.withAppointedLeader(appointedLeaderIndex)
.withConsensusModuleAppVersion(SemanticVersion.compose(1, 0, 0))
.start();
systemTestWatcher.cluster(cluster);

cluster.awaitLeader();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.agrona.CloseHelper;
import org.agrona.DirectBuffer;
import org.agrona.ExpandableArrayBuffer;
import org.agrona.SemanticVersion;
import org.agrona.collections.ArrayUtil;
import org.agrona.collections.IntHashSet;
import org.agrona.collections.MutableBoolean;
Expand Down Expand Up @@ -159,6 +160,7 @@ public final class TestCluster implements AutoCloseable
private File markFileBaseDir;
private String clusterBaseDir;
private ClusterBackup.Configuration.ReplayStart replayStart;
private int consensusModuleAppVersion = SemanticVersion.compose(0, 0, 1);

private TestCluster(
final int staticMemberCount,
Expand Down Expand Up @@ -327,7 +329,8 @@ public TestNode startStaticNode(
.timerServiceSupplier(timerServiceSupplier)
.acceptStandbySnapshots(acceptStandbySnapshots)
.markFileDir(markFileDir)
.deleteDirOnStart(cleanStart);
.deleteDirOnStart(cleanStart)
.appVersion(consensusModuleAppVersion);

nodes[index] = new TestNode(context, dataCollector);

Expand Down Expand Up @@ -489,7 +492,8 @@ public TestNode startStaticNodeFromBackup(final IntFunction<TestNode.TestService
.timerServiceSupplier(timerServiceSupplier)
.acceptStandbySnapshots(acceptStandbySnapshots)
.markFileDir(markFileDir)
.deleteDirOnStart(false);
.deleteDirOnStart(false)
.appVersion(consensusModuleAppVersion);

backupNode = null;
nodes[backupNodeIndex] = new TestNode(context, dataCollector);
Expand Down Expand Up @@ -2057,6 +2061,7 @@ public static final class Builder
private String clusterBaseDir = System.getProperty(
CLUSTER_BASE_DIR_PROP_NAME, CommonContext.getAeronDirectoryName());
private boolean useResponseChannels = false;
private int consensusModuleAppVersion;

public Builder withStaticNodes(final int nodeCount)
{
Expand Down Expand Up @@ -2165,6 +2170,11 @@ public Builder useResponseChannels(final boolean enabled)
return this;
}

public Builder withConsensusModuleAppVersion(int consensusModuleAppVersion) {
this.consensusModuleAppVersion = consensusModuleAppVersion;
return this;
}

public TestCluster start()
{
return start(nodeCount);
Expand Down Expand Up @@ -2196,6 +2206,7 @@ public TestCluster start(final int toStart)
testCluster.markFileBaseDir(markFileBaseDir);
testCluster.clusterBaseDir(clusterBaseDir);
testCluster.replyStart(replayStart);
testCluster.consensusModuleAppVersion(consensusModuleAppVersion);

try
{
Expand Down Expand Up @@ -2247,6 +2258,10 @@ private void invalidInitialResolutions(
this.byMemberInvalidInitialResolutions = byMemberInvalidInitialResolutions;
}

private void consensusModuleAppVersion(int consensusModuleAppVersion) {
this.consensusModuleAppVersion = consensusModuleAppVersion;
}

private void acceptStandbySnapshots(final boolean acceptStandbySnapshots)
{
this.acceptStandbySnapshots = acceptStandbySnapshots;
Expand Down

0 comments on commit 34586a2

Please sign in to comment.