Skip to content

Commit deae6c9

Browse files
authored
chore: Simplified implementation of TransactionGenerator (#18785)
Signed-off-by: Michael Heinrichs <[email protected]>
1 parent 7fb871c commit deae6c9

File tree

10 files changed

+41
-209
lines changed

10 files changed

+41
-209
lines changed

platform-sdk/consensus-otter-tests/src/test/java/org/hiero/otter/test/BirthRoundMigrationTest.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package org.hiero.otter.test;
33

4-
import static org.hiero.otter.fixtures.TransactionGenerator.INFINITE;
5-
64
import java.time.Duration;
75
import org.hiero.consensus.config.EventConfig_;
86
import org.hiero.otter.fixtures.Network;
97
import org.hiero.otter.fixtures.Node;
108
import org.hiero.otter.fixtures.OtterTest;
119
import org.hiero.otter.fixtures.TestEnvironment;
1210
import org.hiero.otter.fixtures.TimeManager;
13-
import org.hiero.otter.fixtures.TransactionGenerator.Distribution;
14-
import org.hiero.otter.fixtures.TransactionGenerator.Rate;
1511

1612
class BirthRoundMigrationTest {
1713

@@ -26,13 +22,13 @@ void testBirthRoundMigration(TestEnvironment env) throws InterruptedException {
2622
// Setup simulation
2723
network.addNodes(4);
2824
network.start(ONE_MINUTE);
29-
env.generator().generateTransactions(INFINITE, Rate.fixedRateWithTps(1000), Distribution.UNIFORM);
25+
env.generator().start();
3026

3127
// Wait for 30 seconds
3228
timeManager.waitFor(THIRTY_SECONDS);
3329

3430
// Initiate the migration
35-
env.generator().pause();
31+
env.generator().stop();
3632
network.prepareUpgrade(ONE_MINUTE);
3733

3834
// update the configuration
@@ -42,7 +38,7 @@ void testBirthRoundMigration(TestEnvironment env) throws InterruptedException {
4238

4339
// restart the network
4440
network.resume(ONE_MINUTE);
45-
env.generator().resume();
41+
env.generator().start();
4642

4743
// Wait for 30 seconds
4844
timeManager.waitFor(THIRTY_SECONDS);

platform-sdk/consensus-otter-tests/src/test/java/org/hiero/otter/test/HappyPathTest.java

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package org.hiero.otter.test;
33

4-
import static org.hiero.otter.fixtures.TransactionGenerator.INFINITE;
5-
64
import java.time.Duration;
75
import org.hiero.otter.fixtures.Network;
86
import org.hiero.otter.fixtures.OtterTest;
97
import org.hiero.otter.fixtures.TestEnvironment;
108
import org.hiero.otter.fixtures.TimeManager;
11-
import org.hiero.otter.fixtures.TransactionGenerator.Distribution;
12-
import org.hiero.otter.fixtures.TransactionGenerator.Rate;
139
import org.hiero.otter.fixtures.Validator.Profile;
1410
import org.hiero.otter.fixtures.turtle.TurtleNode;
1511

@@ -23,7 +19,7 @@ void testHappyPath(TestEnvironment env) throws InterruptedException {
2319
// Setup simulation
2420
network.addNodes(4);
2521
network.start(Duration.ofMinutes(1L));
26-
env.generator().generateTransactions(INFINITE, Rate.fixedRateWithTps(1000), Distribution.UNIFORM);
22+
env.generator().start();
2723

2824
// Wait for two minutes
2925
timeManager.waitFor(Duration.ofMinutes(2L));

platform-sdk/consensus-otter-tests/src/test/java/org/hiero/otter/test/SandboxTest.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package org.hiero.otter.test;
33

4-
import static org.hiero.otter.fixtures.TransactionGenerator.INFINITE;
54
import static org.hiero.otter.fixtures.Validator.EventStreamConfig.ignoreNode;
65
import static org.hiero.otter.fixtures.Validator.LogErrorConfig.ignoreMarkers;
76
import static org.hiero.otter.fixtures.Validator.RatioConfig.within;
@@ -15,8 +14,6 @@
1514
import org.hiero.otter.fixtures.OtterTest;
1615
import org.hiero.otter.fixtures.TestEnvironment;
1716
import org.hiero.otter.fixtures.TimeManager;
18-
import org.hiero.otter.fixtures.TransactionGenerator.Distribution;
19-
import org.hiero.otter.fixtures.TransactionGenerator.Rate;
2017
import org.hiero.otter.fixtures.Validator.Profile;
2118

2219
public class SandboxTest {
@@ -33,7 +30,7 @@ void testConsistencyNDReconnect(TestEnvironment env) throws InterruptedException
3330
// Setup simulation
3431
final List<Node> nodes = network.addNodes(4);
3532
network.start(ONE_MINUTE);
36-
env.generator().generateTransactions(INFINITE, Rate.fixedRateWithTps(1000), Distribution.UNIFORM);
33+
env.generator().start();
3734

3835
// Wait for two minutes
3936
timeManager.waitFor(TWO_MINUTES);
@@ -70,7 +67,7 @@ void testBranching(TestEnvironment env) throws InterruptedException {
7067
network.addNodes(3);
7168
final InstrumentedNode nodeX = network.addInstrumentedNode();
7269
network.start(ONE_MINUTE);
73-
env.generator().generateTransactions(INFINITE, Rate.fixedRateWithTps(1000), Distribution.UNIFORM);
70+
env.generator().start();
7471

7572
// Wait for one minute
7673
timeManager.waitFor(TEN_SECONDS);

platform-sdk/consensus-otter-tests/src/testFixtures/java/module-info.java

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
requires com.swirlds.common.test.fixtures;
88
requires com.swirlds.platform.core.test.fixtures;
99
requires com.swirlds.platform.core;
10+
requires org.hiero.base.utility;
1011
requires org.hiero.consensus.model;
1112
requires com.github.spotbugs.annotations;
1213
requires org.apache.logging.log4j;
Original file line numberDiff line numberDiff line change
@@ -1,79 +1,25 @@
11
// SPDX-License-Identifier: Apache-2.0
22
package org.hiero.otter.fixtures;
33

4-
import edu.umd.cs.findbugs.annotations.NonNull;
5-
import java.time.Instant;
6-
import org.hiero.otter.fixtures.internal.FixedRate;
7-
84
/**
95
* Interface representing a transaction generator.
106
*
11-
* <p>This interface provides methods to generate random transactions and send them to the nodes.
7+
* <p>A {@link TransactionGenerator} generates a steady flow of transaction to all nodes in the
8+
* network. The generator sends 100 transactions to each node per second, which ensures there is
9+
* always at least one transaction waiting to be processed by the event creator.
1210
*/
1311
public interface TransactionGenerator {
1412

15-
/**
16-
* Constant representing an infinite number of transactions.
17-
*/
18-
int INFINITE = -1;
13+
int TPS = 100;
1914

2015
/**
21-
* Generate a specified number of transactions with a given rate and distribution.
22-
*
23-
* @param count the number of transactions to generate
24-
* @param rate the rate at which to generate transactions
25-
* @param distribution the distribution of transactions across the nodes
16+
* Start the generation of transactions with the default transaction factory that uses
17+
* random {@code int} values.
2618
*/
27-
void generateTransactions(int count, @NonNull Rate rate, @NonNull Distribution distribution);
19+
void start();
2820

2921
/**
3022
* Stop the transaction generation.
3123
*/
3224
void stop();
33-
34-
/**
35-
* Pause the transaction generation. Once paused, the transaction generation can be resumed by calling {@link #resume()}.
36-
*/
37-
void pause();
38-
39-
/**
40-
* Resume the transaction generation after it has been paused.
41-
*/
42-
void resume();
43-
44-
/**
45-
* The {@code Rate} class represents the rate at which transactions are generated.
46-
*/
47-
interface Rate {
48-
49-
/**
50-
* Creates a rate that generates transactions at a fixed frequency.
51-
*
52-
* @param tps the number of transactions per second
53-
* @return a {@code Rate} object representing the specified rate
54-
*/
55-
@NonNull
56-
static Rate fixedRateWithTps(final int tps) {
57-
return new FixedRate(tps);
58-
}
59-
60-
/**
61-
* Returns the duration until when the next transaction should be generated in nanoseconds.
62-
*
63-
* @param start the start time of the transaction generation
64-
* @param now the current time
65-
* @return the duration until when the next transaction should be generated
66-
*/
67-
long nextDelayNS(@NonNull Instant start, @NonNull Instant now);
68-
}
69-
70-
/**
71-
* The {@code Distribution} enum represents the distribution of transactions across the nodes.
72-
*/
73-
enum Distribution {
74-
/**
75-
* Transactions are distributed uniformly across the nodes.
76-
*/
77-
UNIFORM
78-
}
7925
}

platform-sdk/consensus-otter-tests/src/testFixtures/java/org/hiero/otter/fixtures/internal/Distributor.java

-10
This file was deleted.

platform-sdk/consensus-otter-tests/src/testFixtures/java/org/hiero/otter/fixtures/internal/FixedRate.java

-28
This file was deleted.

platform-sdk/consensus-otter-tests/src/testFixtures/java/org/hiero/otter/fixtures/internal/UniformDistributor.java

-43
This file was deleted.

platform-sdk/consensus-otter-tests/src/testFixtures/java/org/hiero/otter/fixtures/turtle/TurtleNetwork.java

+4
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ public void resume(@NonNull Duration duration) throws InterruptedException {
163163
*/
164164
@Override
165165
public void tick(@NonNull final Instant now) {
166+
if (state != State.RUNNING) {
167+
return;
168+
}
169+
166170
simulatedNetwork.tick(now);
167171

168172
// Iteration order over nodes does not need to be deterministic -- nodes are not permitted to communicate with

0 commit comments

Comments
 (0)