Skip to content

Commit 2287b3d

Browse files
authored
chore: 13093: Validator - migrate to java module and fix build (#19183)
Signed-off-by: Artur Kugal <[email protected]>
1 parent e3cdf61 commit 2287b3d

File tree

52 files changed

+426
-775
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+426
-775
lines changed

hedera-node/hedera-app/src/main/java/module-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@
6767
exports com.hedera.node.app.workflows;
6868
exports com.hedera.node.app.state.merkle to
6969
com.hedera.node.app.test.fixtures,
70-
com.hedera.node.test.clients;
70+
com.hedera.node.test.clients,
71+
com.swirlds.state.validator;
7172
exports com.hedera.node.app.workflows.dispatcher;
7273
exports com.hedera.node.app.workflows.standalone;
7374
exports com.hedera.node.app.config;

hedera-node/hedera-consensus-service-impl/src/main/java/module-info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727

2828
exports com.hedera.node.app.service.consensus.impl to
2929
com.hedera.node.app,
30-
com.hedera.node.test.clients;
30+
com.hedera.node.test.clients,
31+
com.swirlds.state.validator;
3132
exports com.hedera.node.app.service.consensus.impl.handlers;
3233
exports com.hedera.node.app.service.consensus.impl.handlers.customfee;
3334
exports com.hedera.node.app.service.consensus.impl.records;

hedera-state-validator/build.gradle.kts

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,6 @@ plugins {
44
id("org.hiero.gradle.feature.shadow")
55
}
66

7-
dependencies {
8-
9-
implementation("info.picocli:picocli:4.7.0")
10-
implementation("org.apache.logging.log4j:log4j-api:2.17.2")
11-
implementation("org.apache.logging.log4j:log4j-core:2.17.2")
12-
13-
// used to write json report
14-
implementation("com.google.code.gson:gson:2.10")
15-
}
16-
17-
mainModuleInfo {
18-
requires ("com.hedera.node.app")
19-
requires ("com.hedera.node.app.test.fixtures")
20-
21-
requires ("com.swirlds.merkledb")
22-
23-
24-
// Define the individual libraries
25-
// JUnit Bundle
26-
requires("org.junit.jupiter.api")
27-
requires("org.junit.jupiter.engine")
28-
requires("org.junit.platform.launcher")
29-
30-
}
7+
mainModuleInfo { runtimeOnly("org.junit.jupiter.engine") }
318

329
application.mainClass = "com.hedera.statevalidation.StateOperatorCommand"

hedera-state-validator/src/main/java/com/hedera/statevalidation/Constants.java

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
/*
2-
* Copyright (C) 2023 Hedera Hashgraph, LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
1+
// SPDX-License-Identifier: Apache-2.0
172
package com.hedera.statevalidation;
183

194
import java.nio.file.Path;

hedera-state-validator/src/main/java/com/hedera/statevalidation/IntrospectCommand.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
package com.hedera.statevalidation;
23

4+
import static picocli.CommandLine.*;
5+
36
import com.hedera.statevalidation.introspectors.KvIntrospector;
47
import com.hedera.statevalidation.introspectors.SingletonIntrospector;
58
import com.hedera.statevalidation.parameterresolver.StateResolver;
69
import com.swirlds.platform.state.snapshot.DeserializedSignedState;
710
import com.swirlds.state.State;
8-
import picocli.CommandLine.ParentCommand;
9-
1011
import java.io.IOException;
11-
12-
import static picocli.CommandLine.*;
12+
import picocli.CommandLine.ParentCommand;
1313

1414
@Command(name = "introspect", description = "Introspects the state")
15-
public class IntrospectCommand implements Runnable{
15+
public class IntrospectCommand implements Runnable {
1616

1717
@ParentCommand
1818
private StateOperatorCommand parent;
@@ -38,14 +38,13 @@ public void run() {
3838
throw new RuntimeException(e);
3939
}
4040

41-
if(keyInfo == null) {
41+
if (keyInfo == null) {
4242
// we assume it's a singleton
4343
final SingletonIntrospector introspector = new SingletonIntrospector(state, serviceName, stateName);
4444
introspector.introspect();
4545
} else {
4646
final KvIntrospector introspector = new KvIntrospector(state, serviceName, stateName, keyInfo);
4747
introspector.introspect();
4848
}
49-
5049
}
5150
}

hedera-state-validator/src/main/java/com/hedera/statevalidation/StateOperatorCommand.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
package com.hedera.statevalidation;
23

3-
4+
import java.io.File;
45
import org.apache.logging.log4j.LogManager;
56
import org.apache.logging.log4j.Logger;
67
import picocli.CommandLine;
78
import picocli.CommandLine.Parameters;
89

9-
import java.io.File;
10-
import java.util.concurrent.Callable;
11-
1210
@CommandLine.Command(
1311
name = "operator",
1412
mixinStandardHelpOptions = true,
15-
subcommands = { ValidateCommand.class, IntrospectCommand.class },
16-
description = "CLI tool with validation and introspection modes"
17-
)
13+
subcommands = {ValidateCommand.class, IntrospectCommand.class},
14+
description = "CLI tool with validation and introspection modes")
1815
public class StateOperatorCommand implements Runnable {
1916

2017
private static final Logger log = LogManager.getLogger(StateOperatorCommand.class);
@@ -26,7 +23,6 @@ File getStateDir() {
2623
return stateDir;
2724
}
2825

29-
3026
@Override
3127
public void run() {
3228
// This runs if no subcommand is provided
@@ -44,5 +40,4 @@ public static void main(String[] args) {
4440
throw new RuntimeException(e);
4541
}
4642
}
47-
4843
}
Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
/*
2-
* Copyright (C) 2022-2023 Hedera Hashgraph, LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
1+
// SPDX-License-Identifier: Apache-2.0
172
package com.hedera.statevalidation;
183

4+
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage;
5+
196
import com.hedera.statevalidation.listener.LoggingTestExecutionListener;
207
import com.hedera.statevalidation.listener.ReportingListener;
218
import com.hedera.statevalidation.listener.SummaryGeneratingListener;
22-
import org.apache.logging.log4j.LogManager;
23-
import org.apache.logging.log4j.Logger;
9+
import java.util.concurrent.Callable;
2410
import org.junit.platform.launcher.Launcher;
2511
import org.junit.platform.launcher.LauncherDiscoveryRequest;
2612
import org.junit.platform.launcher.LauncherSession;
@@ -32,27 +18,29 @@
3218
import picocli.CommandLine.Command;
3319
import picocli.CommandLine.ParentCommand;
3420

35-
import java.io.File;
36-
import java.util.concurrent.Callable;
37-
38-
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectPackage;
39-
4021
/**
4122
* This class is an entry point for the validators.
4223
* It is responsible for discovering all tests in the package and running them. Uses provided tags to filter tests.<br>
4324
* All validators are expecting 2 parameters:<br>
4425
* 1. State directory - the directory where the state is stored<br>
4526
* 2. Tag to run - the tag of the test to run (optional) If no tags are provided, all tests are run.<br>
4627
*/
47-
@Command(name = "validate", mixinStandardHelpOptions = true,
28+
@Command(
29+
name = "validate",
30+
mixinStandardHelpOptions = true,
4831
description = "Validates the state of a Mainnet Hedera node")
4932
public class ValidateCommand implements Callable<Integer> {
5033

5134
@ParentCommand
5235
private StateOperatorCommand parent;
5336

54-
@CommandLine.Parameters(arity = "1..*", description = "Tag to run: [stateAnalyzer, internal, leaf, hdhm, account, tokenRelations, rehash, files, compaction]")
55-
private String[] tags = {"stateAnalyzer", "internal", "leaf", "hdhm", "account", "tokenRelations", "rehash", "files", "compaction"};
37+
@CommandLine.Parameters(
38+
arity = "1..*",
39+
description =
40+
"Tag to run: [stateAnalyzer, internal, leaf, hdhm, account, tokenRelations, rehash, files, compaction]")
41+
private String[] tags = {
42+
"stateAnalyzer", "internal", "leaf", "hdhm", "account", "tokenRelations", "rehash", "files", "compaction"
43+
};
5644

5745
@Override
5846
public Integer call() {
@@ -67,12 +55,12 @@ public Integer call() {
6755
SummaryGeneratingListener summaryGeneratingListener = new SummaryGeneratingListener();
6856
try (LauncherSession session = LauncherFactory.openSession()) {
6957
Launcher launcher = session.getLauncher();
70-
launcher.registerTestExecutionListeners(new ReportingListener(), summaryGeneratingListener, new LoggingTestExecutionListener());
58+
launcher.registerTestExecutionListeners(
59+
new ReportingListener(), summaryGeneratingListener, new LoggingTestExecutionListener());
7160
testPlan = launcher.discover(request);
7261
launcher.execute(testPlan);
7362
}
7463

7564
return summaryGeneratingListener.isFailed() ? 1 : 0;
7665
}
77-
78-
}
66+
}

hedera-state-validator/src/main/java/com/hedera/statevalidation/introspectors/IntrospectUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
package com.hedera.statevalidation.introspectors;
23

34
import com.hedera.pbj.runtime.JsonCodec;
4-
55
import java.lang.reflect.Field;
66

77
public final class IntrospectUtils {

hedera-state-validator/src/main/java/com/hedera/statevalidation/introspectors/KvIntrospector.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
package com.hedera.statevalidation.introspectors;
23

4+
import static com.hedera.statevalidation.introspectors.IntrospectUtils.getCodecFor;
5+
36
import com.hedera.hapi.node.base.AccountID;
47
import com.hedera.hapi.node.base.ContractID;
58
import com.hedera.hapi.node.base.FileID;
@@ -13,7 +16,6 @@
1316
import com.hedera.hapi.node.state.contract.SlotKey;
1417
import com.hedera.hapi.node.state.hints.HintsPartyId;
1518
import com.hedera.hapi.node.state.history.ConstructionNodeId;
16-
import com.hedera.hapi.node.state.primitives.ProtoLong;
1719
import com.hedera.hapi.node.state.tss.TssMessageMapKey;
1820
import com.hedera.hapi.node.state.tss.TssVoteMapKey;
1921
import com.hedera.hapi.platform.state.NodeId;
@@ -23,8 +25,6 @@
2325
import com.swirlds.state.State;
2426
import com.swirlds.state.spi.ReadableKVState;
2527

26-
import static com.hedera.statevalidation.introspectors.IntrospectUtils.getCodecFor;
27-
2828
public class KvIntrospector {
2929

3030
private final State state;
@@ -43,7 +43,8 @@ public KvIntrospector(State state, String serviceName, String stateName, String
4343
}
4444

4545
public void introspect() {
46-
ReadableKVState<Object, Object> kvState = state.getReadableStates(serviceName).get(stateName);
46+
ReadableKVState<Object, Object> kvState =
47+
state.getReadableStates(serviceName).get(stateName);
4748
final JsonCodec jsonCodec;
4849
switch (keyType) {
4950
case "EntityNumber" -> jsonCodec = EntityNumber.JSON;

hedera-state-validator/src/main/java/com/hedera/statevalidation/introspectors/SingletonIntrospector.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
package com.hedera.statevalidation.introspectors;
23

3-
import com.swirlds.state.State;
4-
54
import static com.hedera.statevalidation.introspectors.IntrospectUtils.getCodecFor;
65

6+
import com.swirlds.state.State;
7+
78
public class SingletonIntrospector {
89

910
private final State state;
@@ -17,7 +18,8 @@ public SingletonIntrospector(State state, String serviceName, String stateName)
1718
}
1819

1920
public void introspect() {
20-
Object singleton = state.getReadableStates(serviceName).getSingleton(stateName).get();
21+
Object singleton =
22+
state.getReadableStates(serviceName).getSingleton(stateName).get();
2123
System.out.println(getCodecFor(singleton).toJSON(singleton));
2224
}
2325
}

hedera-state-validator/src/main/java/com/hedera/statevalidation/listener/ListenerUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
package com.hedera.statevalidation.listener;
23

34
import org.junit.platform.engine.support.descriptor.MethodSource;
@@ -6,7 +7,8 @@
67
public class ListenerUtils {
78

89
public static String extractTestFullName(TestIdentifier testIdentifier) {
9-
final MethodSource methodSource = (MethodSource) testIdentifier.getSource().orElseThrow();
10+
final MethodSource methodSource =
11+
(MethodSource) testIdentifier.getSource().orElseThrow();
1012
final String methodName = methodSource.getMethodName();
1113
final String className = methodSource.getJavaClass().getSimpleName();
1214
final String displayName = testIdentifier.getDisplayName();

hedera-state-validator/src/main/java/com/hedera/statevalidation/listener/LoggingTestExecutionListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
package com.hedera.statevalidation.listener;
23

34
import static com.hedera.statevalidation.listener.ListenerUtils.extractTestFullName;

hedera-state-validator/src/main/java/com/hedera/statevalidation/listener/ReportingListener.java

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,4 @@
1-
/*
2-
* Copyright (C) 2023 Hedera Hashgraph, LLC
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License");
5-
* you may not use this file except in compliance with the License.
6-
* You may obtain a copy of the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS,
12-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13-
* See the License for the specific language governing permissions and
14-
* limitations under the License.
15-
*/
16-
1+
// SPDX-License-Identifier: Apache-2.0
172
package com.hedera.statevalidation.listener;
183

194
import com.hedera.statevalidation.Constants;
@@ -32,7 +17,9 @@ public class ReportingListener implements org.junit.platform.launcher.TestExecut
3217

3318
@Override
3419
public void testPlanExecutionFinished(TestPlan testPlan) {
35-
log.info("Writing JSON report to [{}]", Constants.REPORT_FILE.toAbsolutePath().toString());
20+
log.info(
21+
"Writing JSON report to [{}]",
22+
Constants.REPORT_FILE.toAbsolutePath().toString());
3623

3724
JsonHelper.writeReport(ReportingFactory.getInstance().report(), Constants.REPORT_FILE);
3825
}

hedera-state-validator/src/main/java/com/hedera/statevalidation/listener/SummaryGeneratingListener.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// SPDX-License-Identifier: Apache-2.0
12
package com.hedera.statevalidation.listener;
23

34
import static com.hedera.statevalidation.listener.ListenerUtils.extractTestFullName;
@@ -60,8 +61,7 @@ public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult
6061
private static void printMessage(TestIdentifier testIdentifier, String message, String color, long timeTaken) {
6162
log.info(String.format(
6263
"%s - %s%s%s, time taken - %s sec",
63-
extractTestFullName(testIdentifier), color, message, ANSI_RESET, timeTaken
64-
));
64+
extractTestFullName(testIdentifier), color, message, ANSI_RESET, timeTaken));
6565
}
6666

6767
public boolean isFailed() {

0 commit comments

Comments
 (0)