1
+ /*
2
+ * Copyright (C) 2024 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
17
package com .hedera .block .server ;
2
18
19
+ import static org .junit .jupiter .api .Assertions .*;
20
+ import static org .mockito .Mockito .*;
21
+
3
22
import com .hedera .block .protos .BlockStreamServiceGrpcProto ;
4
23
import com .hedera .block .server .mediator .StreamMediator ;
5
24
import com .hedera .block .server .persistence .BlockPersistenceHandler ;
6
- import io .grpc .Status ;
7
25
import io .grpc .stub .StreamObserver ;
26
+ import java .util .Optional ;
8
27
import org .junit .jupiter .api .Test ;
9
28
import org .junit .jupiter .api .extension .ExtendWith ;
10
29
import org .mockito .Mock ;
11
30
import org .mockito .junit .jupiter .MockitoExtension ;
12
31
13
- import java .util .Optional ;
14
-
15
- import static org .junit .jupiter .api .Assertions .*;
16
- import static org .mockito .Mockito .*;
17
-
18
32
@ ExtendWith (MockitoExtension .class )
19
33
class BlockStreamServiceTest {
20
34
21
35
private final long TIMEOUT_THRESHOLD_MILLIS = 52L ;
22
36
23
-
24
- @ Mock
25
- private StreamObserver <BlockStreamServiceGrpcProto .Block > responseObserver ;
37
+ @ Mock private StreamObserver <BlockStreamServiceGrpcProto .Block > responseObserver ;
26
38
27
39
@ Mock
28
40
private BlockPersistenceHandler <BlockStreamServiceGrpcProto .Block > blockPersistenceHandler ;
29
41
30
42
@ Mock
31
43
private StreamMediator <
32
- BlockStreamServiceGrpcProto .Block ,
33
- BlockStreamServiceGrpcProto .BlockResponse >
44
+ BlockStreamServiceGrpcProto .Block , BlockStreamServiceGrpcProto .BlockResponse >
34
45
streamMediator ;
35
46
36
47
@ Test
37
48
void getBlockHappyPath () {
38
- BlockStreamServiceGrpcProto .Block block = BlockStreamServiceGrpcProto .Block .newBuilder ().setId (1 ).build ();
39
- BlockStreamService blockStreamService = new BlockStreamService (TIMEOUT_THRESHOLD_MILLIS , streamMediator , blockPersistenceHandler );
40
- when (blockPersistenceHandler .read (1 )).thenReturn (Optional .of (BlockStreamServiceGrpcProto .Block .newBuilder ().setId (1 ).build ()));
49
+ BlockStreamServiceGrpcProto .Block block =
50
+ BlockStreamServiceGrpcProto .Block .newBuilder ().setId (1 ).build ();
51
+ BlockStreamService blockStreamService =
52
+ new BlockStreamService (
53
+ TIMEOUT_THRESHOLD_MILLIS , streamMediator , blockPersistenceHandler );
54
+ when (blockPersistenceHandler .read (1 ))
55
+ .thenReturn (
56
+ Optional .of (
57
+ BlockStreamServiceGrpcProto .Block .newBuilder ().setId (1 ).build ()));
41
58
blockStreamService .getBlock (block , responseObserver );
42
59
verify (responseObserver , times (1 )).onNext (block );
43
60
}
44
61
45
62
@ Test
46
63
void getBlockErrorPath () {
47
- BlockStreamServiceGrpcProto .Block block = BlockStreamServiceGrpcProto .Block .newBuilder ().setId (1 ).build ();
48
- BlockStreamService blockStreamService = new BlockStreamService (TIMEOUT_THRESHOLD_MILLIS , streamMediator , blockPersistenceHandler );
64
+ BlockStreamServiceGrpcProto .Block block =
65
+ BlockStreamServiceGrpcProto .Block .newBuilder ().setId (1 ).build ();
66
+ BlockStreamService blockStreamService =
67
+ new BlockStreamService (
68
+ TIMEOUT_THRESHOLD_MILLIS , streamMediator , blockPersistenceHandler );
49
69
when (blockPersistenceHandler .read (1 )).thenReturn (Optional .empty ());
50
70
blockStreamService .getBlock (block , responseObserver );
51
- verify (responseObserver , times (1 )).onNext (BlockStreamServiceGrpcProto .Block .newBuilder ().setId (0 ).build ());
71
+ verify (responseObserver , times (1 ))
72
+ .onNext (BlockStreamServiceGrpcProto .Block .newBuilder ().setId (0 ).build ());
52
73
}
53
- }
74
+ }
0 commit comments