1
1
// SPDX-License-Identifier: Apache-2.0
2
2
package com .swirlds .platform .event .preconsensus ;
3
3
4
+ import static org .hiero .base .utility .test .fixtures .RandomUtils .getRandomPrintSeed ;
4
5
import static org .junit .jupiter .api .Assertions .assertEquals ;
5
6
import static org .junit .jupiter .api .Assertions .assertFalse ;
6
7
import static org .junit .jupiter .api .Assertions .assertTrue ;
11
12
import static org .mockito .Mockito .verify ;
12
13
import static org .mockito .Mockito .when ;
13
14
14
- import com .hedera .hapi .platform .event .EventDescriptor ;
15
- import com .hedera .pbj .runtime .io .buffer .Bytes ;
16
15
import com .swirlds .common .context .PlatformContext ;
17
16
import com .swirlds .config .api .Configuration ;
18
17
import com .swirlds .config .extensions .test .fixtures .TestConfigBuilder ;
18
+ import com .swirlds .platform .test .fixtures .event .TestingEventBuilder ;
19
19
import java .io .IOException ;
20
- import org .hiero .consensus .model .crypto .DigestType ;
21
- import org .hiero .consensus .model .event .EventDescriptorWrapper ;
20
+ import java .util .Random ;
22
21
import org .hiero .consensus .model .event .PlatformEvent ;
23
22
import org .hiero .consensus .model .hashgraph .EventWindow ;
24
23
import org .junit .jupiter .api .BeforeEach ;
@@ -30,13 +29,24 @@ class CommonPcesWriterTest {
30
29
private PcesFileManager fileManager ;
31
30
private CommonPcesWriter commonPcesWriter ;
32
31
private PcesMutableFile pcesMutableFile ;
32
+ private PlatformEvent event ;
33
33
34
34
@ BeforeEach
35
35
void setUp () throws Exception {
36
36
final Configuration configuration = new TestConfigBuilder ().getOrCreateConfig ();
37
37
final PlatformContext platformContext = mock (PlatformContext .class );
38
38
when (platformContext .getConfiguration ()).thenReturn (configuration );
39
-
39
+ final Random random = getRandomPrintSeed ();
40
+ event = new TestingEventBuilder (random )
41
+ .setAppTransactionCount (3 )
42
+ .setSystemTransactionCount (1 )
43
+ .setSelfParent (
44
+ new TestingEventBuilder (random ).setBirthRound (150 ).build ())
45
+ .setOtherParent (
46
+ new TestingEventBuilder (random ).setBirthRound (150 ).build ())
47
+ .overrideOtherParentGeneration (150 )
48
+ .setBirthRound (150 )
49
+ .build ();
40
50
fileManager = mock (PcesFileManager .class );
41
51
final PcesFile pcesFile = mock (PcesFile .class );
42
52
when (fileManager .getNextFileDescriptor (anyLong (), anyLong ())).thenReturn (pcesFile );
@@ -63,7 +73,7 @@ void testBeginStreamingNewEventsAlreadyStreaming() {
63
73
@ Test
64
74
void testRegisterDiscontinuity () throws IOException {
65
75
commonPcesWriter .beginStreamingNewEvents ();
66
- commonPcesWriter .prepareOutputStream (mock ( PlatformEvent . class ) );
76
+ commonPcesWriter .prepareOutputStream (event );
67
77
commonPcesWriter .registerDiscontinuity (10L );
68
78
69
79
// Verify file closing and file manager interactions
@@ -92,22 +102,14 @@ void testSetMinimumAncientIdentifierToStore() throws IOException {
92
102
93
103
@ Test
94
104
void testPrepareOutputStreamCreatesNewFile () throws IOException {
95
- PlatformEvent mockEvent = mock (PlatformEvent .class );
96
- when (mockEvent .getDescriptor ())
97
- .thenReturn (new EventDescriptorWrapper (EventDescriptor .newBuilder ()
98
- .birthRound (150 )
99
- .generation (150 )
100
- .hash (Bytes .wrap (new byte [DigestType .SHA_384 .digestLength ()]))
101
- .build ()));
102
-
103
- boolean fileClosed = commonPcesWriter .prepareOutputStream (mockEvent );
105
+ boolean fileClosed = commonPcesWriter .prepareOutputStream (event );
104
106
assertFalse (fileClosed , "A new file should have been created but not closed." );
105
107
}
106
108
107
109
@ Test
108
110
void testCloseCurrentMutableFile () throws IOException {
109
111
commonPcesWriter .beginStreamingNewEvents ();
110
- commonPcesWriter .prepareOutputStream (mock ( PlatformEvent . class ) );
112
+ commonPcesWriter .prepareOutputStream (event );
111
113
commonPcesWriter .closeCurrentMutableFile ();
112
114
verify (pcesMutableFile , times (1 )).close ();
113
115
}
0 commit comments