Skip to content

Commit 0f6dc85

Browse files
maru-cluster-support no EL node (#462)
1 parent 8064132 commit 0f6dc85

File tree

3 files changed

+30
-22
lines changed

3 files changed

+30
-22
lines changed

jvm-libs/test-utils/src/main/kotlin/maru/test/cluster/MaruCluster.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,28 @@ class MaruCluster(
117117

118118
private fun createNodeBuilder(
119119
label: String,
120+
addBesu: Boolean = false,
120121
configurator: (NodeBuilder) -> Unit,
121122
): NodeBuilder {
122123
assertUniqueLabel(label)
123124
return NodeBuilder(
124125
maruConfigTemplate = maruConfigTemplate,
125126
clusterDataDir = maruClusterDataDir,
126127
nodeLabel = label,
128+
createDefaultElBesuNode = addBesu,
127129
).also(configurator)
128130
}
129131

130132
@Synchronized
131133
fun addNode(
132134
label: String,
135+
addBesu: Boolean = false,
133136
configurator: (NodeBuilder) -> Unit = {},
134137
): MaruCluster {
135138
if (runningState == RunningState.RUNNING || runningState == RunningState.STARTING) {
136-
addNewExtraNodeAndStart(label, configurator)
139+
addNewExtraNodeAndStart(label, addBesu, configurator)
137140
} else {
138-
nodesBuilders.add(createNodeBuilder(label, configurator))
141+
nodesBuilders.add(createNodeBuilder(label, addBesu, configurator))
139142
}
140143
return this
141144
}
@@ -145,14 +148,15 @@ class MaruCluster(
145148
*/
146149
private fun addNewExtraNodeAndStart(
147150
nodeLabel: String,
151+
addBesu: Boolean = false,
148152
configurator: (NodeBuilder) -> Unit = {},
149153
): MaruCluster {
150-
val nodeStatConfigs =
151-
createNodeBuilder(nodeLabel, configurator)
154+
val nodeStartConfigs =
155+
createNodeBuilder(nodeLabel, addBesu, configurator)
152156
.build(genesisFactory::besuGenesis, besuCluster)
153157
val node =
154158
buildClusterNode(
155-
nodeStartingConfig = nodeStatConfigs,
159+
nodeStartingConfig = nodeStartConfigs,
156160
bootNodesEnrs = getBootnodesEnrs(),
157161
)
158162
nodes += node
@@ -162,9 +166,10 @@ class MaruCluster(
162166
@Synchronized
163167
fun addNode(
164168
role: NodeRole,
169+
withBesuEl: Boolean = false,
165170
configurator: (NodeBuilder) -> Unit = {},
166171
): MaruCluster =
167-
addNode(label = role.name.lowercase()) { nodeBuilder ->
172+
addNode(label = role.name.lowercase(), withBesuEl) { nodeBuilder ->
168173
nodeBuilder.withRole(role).let(configurator)
169174
}
170175

jvm-libs/test-utils/src/main/kotlin/maru/test/cluster/NodeBuilder.kt

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ class NodeBuilder(
1717
maruConfigTemplate: MaruConfig,
1818
var nodeLabel: String,
1919
val clusterDataDir: Path,
20+
val createDefaultElBesuNode: Boolean,
2021
) {
2122
class NodeBuildingConfig(
2223
val nodeRole: NodeRole,
@@ -55,11 +56,16 @@ class NodeBuilder(
5556
),
5657
)
5758

58-
// fun withBesu(besuBuilder: () -> BesuNode): NodeBuilder {
59+
// fun withElBesu(besuBuilder: () -> BesuNode): NodeBuilder {
5960
// this.elNodeBuilder = { BesuElNode(besu = besuBuilder(), besuCluster = besuCluster) }
6061
// return this
6162
// }
6263

64+
fun withElNode(elNodeBuilder: ElNodeBuilder): NodeBuilder {
65+
this.elNodeBuilder = elNodeBuilder
66+
return this
67+
}
68+
6369
fun withRole(nodeRole: NodeRole): NodeBuilder {
6470
this.nodeRole = nodeRole
6571
return this
@@ -101,7 +107,7 @@ class NodeBuilder(
101107
besuGenesisProvider: () -> String,
102108
besuCluster: BesuCluster,
103109
) {
104-
if (elNodeBuilder == null) {
110+
if (elNodeBuilder == null && createDefaultElBesuNode) {
105111
this.elNodeBuilder = {
106112
BesuElNode(
107113
BesuFactory.buildTestBesu(
@@ -123,6 +129,9 @@ class NodeBuilder(
123129
if (!this::nodeRole.isInitialized) {
124130
nodeRole = getNodeRoleFromLabel(this.nodeLabel)
125131
}
132+
require(!(nodeRole.isSequencer() && elNodeBuilder == null)) {
133+
"Node with $nodeRole role needs an EL node builder defined"
134+
}
126135

127136
return NodeBuildingConfig(
128137
maruConfig = this.maruConfig,

jvm-libs/test-utils/src/test/kotlin/maru/test/MaruClusterTest.kt

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,9 @@ import org.assertj.core.api.Assertions.assertThat
2828
import org.awaitility.Awaitility.await
2929
import org.junit.jupiter.api.AfterEach
3030
import org.junit.jupiter.api.BeforeEach
31-
import org.junit.jupiter.api.MethodOrderer
3231
import org.junit.jupiter.api.Order
3332
import org.junit.jupiter.api.Test
34-
import org.junit.jupiter.api.TestMethodOrder
35-
import org.junit.jupiter.api.parallel.Execution
36-
import org.junit.jupiter.api.parallel.ExecutionMode
3733

38-
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
39-
@Execution(ExecutionMode.SAME_THREAD)
4034
class MaruClusterTest {
4135
private lateinit var cluster: MaruCluster
4236

@@ -60,12 +54,11 @@ class MaruClusterTest {
6054
}
6155

6256
@Test
63-
@Order(1)
6457
fun `should allow to retrieve nodes by label`() {
6558
cluster =
6659
MaruCluster()
6760
.addNode(NodeRole.Follower)
68-
.addNode(NodeRole.Sequencer)
61+
.addNode(NodeRole.Sequencer, withBesuEl = true)
6962
.addNode("follower-special")
7063
.start()
7164

@@ -88,7 +81,7 @@ class MaruClusterTest {
8881
ElFork.Prague,
8982
),
9083
),
91-
).addNode(NodeRole.Sequencer) { nodeBuilder ->
84+
).addNode(NodeRole.Sequencer, withBesuEl = true) { nodeBuilder ->
9285
nodeBuilder.withLabel("sequencer")
9386
}.start()
9487

@@ -132,7 +125,7 @@ class MaruClusterTest {
132125
ElFork.Prague,
133126
),
134127
),
135-
).addNode("sequencer")
128+
).addNode("sequencer", addBesu = true)
136129
.start()
137130

138131
await()
@@ -153,7 +146,7 @@ class MaruClusterTest {
153146
fun `should instantiate multiple nodes in the cluster with static peering and sync`() {
154147
cluster =
155148
MaruCluster()
156-
.addNode("sequencer")
149+
.addNode("sequencer", addBesu = true)
157150
.addNode("follower-internal-0") { nodeBuilder ->
158151
nodeBuilder
159152
.staticPeers(listOf("sequencer"))
@@ -163,10 +156,11 @@ class MaruClusterTest {
163156
}.start()
164157

165158
await()
159+
.apply { }
166160
.pollInterval(1.seconds.toJavaDuration())
167161
.atMost(120.seconds.toJavaDuration())
168162
.untilAsserted {
169-
cluster.assertNodesAreSyncedUpTo(targetBlockNumber = 5UL)
163+
cluster.assertNodesAreSyncedUpTo(targetBlockNumber = 3UL)
170164
}
171165
}
172166

@@ -176,7 +170,7 @@ class MaruClusterTest {
176170
cluster =
177171
MaruCluster()
178172
.addNode("bootnode-1")
179-
.addNode("sequencer")
173+
.addNode("sequencer", addBesu = true)
180174
.addNode("follower-internal-0")
181175
.start()
182176
val followers = cluster.nodes(NodeRole.Follower)
@@ -203,7 +197,7 @@ class MaruClusterTest {
203197
cluster =
204198
MaruCluster()
205199
.addNode("bootnode-0")
206-
.addNode("sequencer")
200+
.addNode("sequencer", addBesu = true)
207201
.addNode("follower-internal-0")
208202
.start()
209203

0 commit comments

Comments
 (0)