|
43 | 43 | import com.swirlds.common.test.fixtures.merkle.dummy.DummyMerkleLeaf2;
|
44 | 44 | import com.swirlds.common.test.fixtures.merkle.dummy.DummyMerkleNode;
|
45 | 45 | import com.swirlds.common.test.fixtures.platform.TestPlatformContextBuilder;
|
| 46 | +import com.swirlds.common.threading.manager.ThreadManager; |
46 | 47 | import com.swirlds.common.threading.pool.StandardWorkGroup;
|
47 | 48 | import java.io.ByteArrayOutputStream;
|
48 | 49 | import java.io.IOException;
|
@@ -990,51 +991,108 @@ public static <T extends MerkleNode> T testSynchronization(
|
990 | 991 | final TeachingSynchronizer teacher;
|
991 | 992 |
|
992 | 993 | if (latencyMilliseconds == 0) {
|
993 |
| - learner = new LearningSynchronizer( |
994 |
| - getStaticThreadManager(), |
995 |
| - streams.getLearnerInput(), |
996 |
| - streams.getLearnerOutput(), |
997 |
| - startingTree, |
998 |
| - streams::disconnect, |
999 |
| - reconnectConfig); |
| 994 | + learner = |
| 995 | + new LearningSynchronizer( |
| 996 | + getStaticThreadManager(), |
| 997 | + streams.getLearnerInput(), |
| 998 | + streams.getLearnerOutput(), |
| 999 | + startingTree, |
| 1000 | + streams::disconnect, |
| 1001 | + reconnectConfig) { |
| 1002 | + |
| 1003 | + @Override |
| 1004 | + protected StandardWorkGroup createStandardWorkGroup( |
| 1005 | + ThreadManager threadManager, |
| 1006 | + Runnable breakConnection, |
| 1007 | + Function<Throwable, Boolean> reconnectExceptionListener) { |
| 1008 | + return new StandardWorkGroup( |
| 1009 | + threadManager, |
| 1010 | + "test-learning-synchronizer", |
| 1011 | + breakConnection, |
| 1012 | + reconnectExceptionListener, |
| 1013 | + true); |
| 1014 | + } |
| 1015 | + }; |
1000 | 1016 | final PlatformContext platformContext =
|
1001 | 1017 | TestPlatformContextBuilder.create().build();
|
1002 |
| - teacher = new TeachingSynchronizer( |
1003 |
| - platformContext.getConfiguration(), |
1004 |
| - Time.getCurrent(), |
1005 |
| - getStaticThreadManager(), |
1006 |
| - streams.getTeacherInput(), |
1007 |
| - streams.getTeacherOutput(), |
1008 |
| - desiredTree, |
1009 |
| - streams::disconnect, |
1010 |
| - reconnectConfig); |
| 1018 | + teacher = |
| 1019 | + new TeachingSynchronizer( |
| 1020 | + platformContext.getConfiguration(), |
| 1021 | + Time.getCurrent(), |
| 1022 | + getStaticThreadManager(), |
| 1023 | + streams.getTeacherInput(), |
| 1024 | + streams.getTeacherOutput(), |
| 1025 | + desiredTree, |
| 1026 | + streams::disconnect, |
| 1027 | + reconnectConfig) { |
| 1028 | + @Override |
| 1029 | + protected StandardWorkGroup createStandardWorkGroup( |
| 1030 | + ThreadManager threadManager, |
| 1031 | + Runnable breakConnection, |
| 1032 | + Function<Throwable, Boolean> exceptionListener) { |
| 1033 | + return new StandardWorkGroup( |
| 1034 | + threadManager, |
| 1035 | + "test-teaching-synchronizer", |
| 1036 | + breakConnection, |
| 1037 | + exceptionListener, |
| 1038 | + true); |
| 1039 | + } |
| 1040 | + }; |
1011 | 1041 | } else {
|
1012 |
| - learner = new LaggingLearningSynchronizer( |
1013 |
| - streams.getLearnerInput(), |
1014 |
| - streams.getLearnerOutput(), |
1015 |
| - startingTree, |
1016 |
| - latencyMilliseconds, |
1017 |
| - streams::disconnect, |
1018 |
| - reconnectConfig); |
| 1042 | + learner = |
| 1043 | + new LaggingLearningSynchronizer( |
| 1044 | + streams.getLearnerInput(), |
| 1045 | + streams.getLearnerOutput(), |
| 1046 | + startingTree, |
| 1047 | + latencyMilliseconds, |
| 1048 | + streams::disconnect, |
| 1049 | + reconnectConfig) { |
| 1050 | + @Override |
| 1051 | + protected StandardWorkGroup createStandardWorkGroup( |
| 1052 | + ThreadManager threadManager, |
| 1053 | + Runnable breakConnection, |
| 1054 | + Function<Throwable, Boolean> reconnectExceptionListener) { |
| 1055 | + return new StandardWorkGroup( |
| 1056 | + threadManager, |
| 1057 | + "test-learning-synchronizer", |
| 1058 | + breakConnection, |
| 1059 | + reconnectExceptionListener, |
| 1060 | + true); |
| 1061 | + } |
| 1062 | + }; |
1019 | 1063 | final PlatformContext platformContext =
|
1020 | 1064 | TestPlatformContextBuilder.create().build();
|
1021 |
| - teacher = new LaggingTeachingSynchronizer( |
1022 |
| - platformContext, |
1023 |
| - streams.getTeacherInput(), |
1024 |
| - streams.getTeacherOutput(), |
1025 |
| - desiredTree, |
1026 |
| - latencyMilliseconds, |
1027 |
| - streams::disconnect, |
1028 |
| - reconnectConfig); |
| 1065 | + teacher = |
| 1066 | + new LaggingTeachingSynchronizer( |
| 1067 | + platformContext, |
| 1068 | + streams.getTeacherInput(), |
| 1069 | + streams.getTeacherOutput(), |
| 1070 | + desiredTree, |
| 1071 | + latencyMilliseconds, |
| 1072 | + streams::disconnect, |
| 1073 | + reconnectConfig) { |
| 1074 | + @Override |
| 1075 | + protected StandardWorkGroup createStandardWorkGroup( |
| 1076 | + ThreadManager threadManager, |
| 1077 | + Runnable breakConnection, |
| 1078 | + Function<Throwable, Boolean> reconnectExceptionListener) { |
| 1079 | + return new StandardWorkGroup( |
| 1080 | + threadManager, |
| 1081 | + "test-teaching-synchronizer", |
| 1082 | + breakConnection, |
| 1083 | + reconnectExceptionListener, |
| 1084 | + true); |
| 1085 | + } |
| 1086 | + }; |
1029 | 1087 | }
|
1030 | 1088 |
|
1031 | 1089 | final AtomicReference<Throwable> firstReconnectException = new AtomicReference<>();
|
1032 | 1090 | final Function<Throwable, Boolean> exceptionListener = t -> {
|
1033 | 1091 | firstReconnectException.compareAndSet(null, t);
|
1034 | 1092 | return false;
|
1035 | 1093 | };
|
1036 |
| - final StandardWorkGroup workGroup = |
1037 |
| - new StandardWorkGroup(getStaticThreadManager(), "synchronization-test", null, exceptionListener); |
| 1094 | + final StandardWorkGroup workGroup = new StandardWorkGroup( |
| 1095 | + getStaticThreadManager(), "synchronization-test", null, exceptionListener, true); |
1038 | 1096 | workGroup.execute("teaching-synchronizer-main", () -> teachingSynchronizerThread(teacher));
|
1039 | 1097 | workGroup.execute("learning-synchronizer-main", () -> learningSynchronizerThread(learner));
|
1040 | 1098 |
|
|
0 commit comments