This is an automated email from the ASF dual-hosted git repository.
dcapwell pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/cassandra-accord.git
The following commit(s) were added to refs/heads/trunk by this push:
new 25f23ffe TopologyMixupTestBase does not fix replication factor for
Keyspaces after reaching rf=3 (#129)
25f23ffe is described below
commit 25f23ffec439a921387ca249908798b9cc7d4620
Author: dcapwell <[email protected]>
AuthorDate: Thu Oct 24 15:42:49 2024 -0700
TopologyMixupTestBase does not fix replication factor for Keyspaces after
reaching rf=3 (#129)
patch by David Capwell; reviewed by Alex Petrov for CASSANDRA-19975
---
.../test/java/accord/impl/mock/MockCluster.java | 3 +-
.../src/test/java/accord/utils/Property.java | 51 ++++++++++++++++++++--
.../test/java/accord/utils/async/TimeoutUtils.java | 4 +-
3 files changed, 52 insertions(+), 6 deletions(-)
diff --git a/accord-core/src/test/java/accord/impl/mock/MockCluster.java
b/accord-core/src/test/java/accord/impl/mock/MockCluster.java
index b3da2479..a7abceb7 100644
--- a/accord-core/src/test/java/accord/impl/mock/MockCluster.java
+++ b/accord-core/src/test/java/accord/impl/mock/MockCluster.java
@@ -390,11 +390,12 @@ public class MockCluster implements Network,
AutoCloseable, Iterable<Node>
public static class Clock implements TimeService
{
private final AtomicLong now;
- private final ToLongFunction<TimeUnit> elapsed =
elapsedWrapperFromNonMonotonicSource(TimeUnit.MILLISECONDS, this::now);
+ private final ToLongFunction<TimeUnit> elapsed;
public Clock(long now)
{
this.now = new AtomicLong(now);
+ this.elapsed =
elapsedWrapperFromNonMonotonicSource(TimeUnit.MILLISECONDS, this::now);
}
public long increment(long by)
diff --git a/accord-core/src/test/java/accord/utils/Property.java
b/accord-core/src/test/java/accord/utils/Property.java
index 95ea50bd..64ad439f 100644
--- a/accord-core/src/test/java/accord/utils/Property.java
+++ b/accord-core/src/test/java/accord/utils/Property.java
@@ -32,6 +32,7 @@ import java.util.Objects;
import java.util.Set;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
+import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
@@ -212,9 +213,21 @@ public class Property
String stateStr = state == null ? null :
state.toString().replace("\n", "\n\t\t");
sb.append("\tState: ").append(stateStr).append(": ").append(state ==
null ? "unknown type" : state.getClass().getCanonicalName()).append('\n');
sb.append("\tHistory:").append('\n');
+ addList(sb, "\t\t", history);
+ return sb.toString();
+ }
+
+ private static void addList(StringBuilder sb, String prefix, List<String>
list)
+ {
int idx = 0;
- for (var event : history)
- sb.append("\t\t").append(++idx).append(":
").append(event).append('\n');
+ for (var event : list)
+ sb.append(prefix).append(++idx).append(":
").append(event).append('\n');
+ }
+
+ public static String formatList(String prefix, List<String> list)
+ {
+ StringBuilder sb = new StringBuilder();
+ addList(sb, prefix, list);
return sb.toString();
}
@@ -467,6 +480,7 @@ public class Property
}
commands.destroySut(sut, null);
commands.destroyState(state, null);
+ commands.onSuccess(state, sut, history);
}
catch (Throwable t)
{
@@ -501,7 +515,7 @@ public class Property
cmd.process(state, sut);
return;
}
- TimeoutUtils.runBlocking(stepTimeout, "Stateful Step " + id, () ->
cmd.process(state, sut));
+ TimeoutUtils.runBlocking(stepTimeout, "Stateful Step " + id + ": "
+ cmd.detailed(state), () -> cmd.process(state, sut));
}
}
@@ -682,6 +696,7 @@ public class Property
{
Gen<State> genInitialState() throws Throwable;
SystemUnderTest createSut(State state) throws Throwable;
+ default void onSuccess(State state, SystemUnderTest sut, List<String>
history) throws Throwable {}
default void destroyState(State state, @Nullable Throwable cause)
throws Throwable {}
default void destroySut(SystemUnderTest sut, @Nullable Throwable
cause) throws Throwable {}
Gen<Command<State, SystemUnderTest, ?>> commands(State state) throws
Throwable;
@@ -697,6 +712,11 @@ public class Property
return new CommandsBuilder<>(stateGen, ignore -> null);
}
+ public interface StatefulSuccess<State, SystemUnderTest>
+ {
+ void apply(State state, SystemUnderTest sut, List<String> history)
throws Throwable;
+ }
+
public static class CommandsBuilder<State, SystemUnderTest>
{
public interface Setup<State, SystemUnderTest>
@@ -717,6 +737,9 @@ public class Property
private FailingBiConsumer<State, Throwable> destroyState = null;
@Nullable
private FailingBiConsumer<SystemUnderTest, Throwable> destroySut =
null;
+ @Nullable
+ private BiFunction<State, Gen<Command<State, SystemUnderTest, ?>>,
Gen<Command<State, SystemUnderTest, ?>>> commandsTransformer = null;
+ private final List<StatefulSuccess<State, SystemUnderTest>> onSuccess
= new ArrayList<>();
public CommandsBuilder(Supplier<Gen<State>> stateGen, Function<State,
SystemUnderTest> sutFactory)
{
@@ -837,6 +860,18 @@ public class Property
return this;
}
+ public CommandsBuilder<State, SystemUnderTest>
commandsTransformer(BiFunction<State, Gen<Command<State, SystemUnderTest, ?>>,
Gen<Command<State, SystemUnderTest, ?>>> commandsTransformer)
+ {
+ this.commandsTransformer = commandsTransformer;
+ return this;
+ }
+
+ public CommandsBuilder<State, SystemUnderTest>
onSuccess(StatefulSuccess<State, SystemUnderTest> fn)
+ {
+ onSuccess.add(fn);
+ return this;
+ }
+
public Commands<State, SystemUnderTest> build()
{
Gen<Setup<State, SystemUnderTest>> commandsGen;
@@ -917,7 +952,8 @@ public class Property
{
if (preCommands != null)
preCommands.accept(state);
- return commandsGen.map((rs, setup) -> setup.setup(rs,
state));
+ Gen<Command<State, SystemUnderTest, ?>> map =
commandsGen.map((rs, setup) -> setup.setup(rs, state));
+ return commandsTransformer == null ? map :
commandsTransformer.apply(state, map);
}
@Override
@@ -934,6 +970,13 @@ public class Property
if (destroySut != null)
destroySut.accept(sut, cause);
}
+
+ @Override
+ public void onSuccess(State state, SystemUnderTest sut,
List<String> history) throws Throwable
+ {
+ for (var fn : onSuccess)
+ fn.apply(state, sut, history);
+ }
};
}
diff --git a/accord-core/src/test/java/accord/utils/async/TimeoutUtils.java
b/accord-core/src/test/java/accord/utils/async/TimeoutUtils.java
index 9754d604..2b5b69a0 100644
--- a/accord-core/src/test/java/accord/utils/async/TimeoutUtils.java
+++ b/accord-core/src/test/java/accord/utils/async/TimeoutUtils.java
@@ -59,7 +59,9 @@ public class TimeoutUtils
catch (TimeoutException e)
{
t.interrupt();
- throw e;
+ TimeoutException e2 = new TimeoutException(threadName);
+ e2.setStackTrace(e.getStackTrace());
+ throw e2;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]