@@ -131,7 +131,7 @@ public void testWriteFailure(boolean failWithException) throws ExecutionExceptio
131
131
when (trx .getStateMachineContext ()).thenReturn (context );
132
132
133
133
setUpMockDispatcherReturn (failWithException );
134
- setUpMockRequestProto (context );
134
+ setUpMockRequestProtoReturn (context , "Test Data" , 1 , 1 );
135
135
136
136
AtomicReference <Throwable > throwable = new AtomicReference <>(null );
137
137
Function <Throwable , ? extends Message > throwableSetter = getThrowableSetter (throwable );
@@ -144,13 +144,7 @@ public void testWriteFailure(boolean failWithException) throws ExecutionExceptio
144
144
assertResults (failWithException , throwable );
145
145
146
146
// Writing data to another container(containerId 2) should also fail.
147
- when (context .getRequestProto ()).thenReturn (ContainerProtos .ContainerCommandRequestProto .newBuilder ()
148
- .setCmdType (ContainerProtos .Type .WriteChunk ).setWriteChunk (
149
- ContainerProtos .WriteChunkRequestProto .newBuilder ().setData (ByteString .copyFromUtf8 ("Test Data" ))
150
- .setBlockID (
151
- ContainerProtos .DatanodeBlockID .newBuilder ().setContainerID (2 ).setLocalID (1 ).build ()).build ())
152
- .setContainerID (2 )
153
- .setDatanodeUuid (UUID .randomUUID ().toString ()).build ());
147
+ setUpMockRequestProtoReturn (context , "Test Data" , 2 , 1 );
154
148
stateMachine .write (entryNext , trx ).exceptionally (throwableSetter ).get ();
155
149
verify (dispatcher , times (0 )).dispatch (any (ContainerProtos .ContainerCommandRequestProto .class ),
156
150
any (DispatcherContext .class ));
@@ -170,13 +164,15 @@ public final void setUpMockDispatcherReturn(boolean failWithException) {
170
164
}
171
165
}
172
166
173
- public final void setUpMockRequestProto (ContainerStateMachine .Context context ) {
167
+ public final void setUpMockRequestProtoReturn (ContainerStateMachine .Context context , String content ,
168
+ int containerId , int localId ) {
174
169
when (context .getRequestProto ()).thenReturn (ContainerProtos .ContainerCommandRequestProto .newBuilder ()
175
170
.setCmdType (ContainerProtos .Type .WriteChunk ).setWriteChunk (
176
- ContainerProtos .WriteChunkRequestProto .newBuilder ().setData (ByteString .copyFromUtf8 ("Test Data" ))
171
+ ContainerProtos .WriteChunkRequestProto .newBuilder ().setData (ByteString .copyFromUtf8 (content ))
177
172
.setBlockID (
178
- ContainerProtos .DatanodeBlockID .newBuilder ().setContainerID (1 ).setLocalID (1 ).build ()).build ())
179
- .setContainerID (1 )
173
+ ContainerProtos .DatanodeBlockID .newBuilder ().setContainerID (containerId )
174
+ .setLocalID (localId ).build ()).build ())
175
+ .setContainerID (containerId )
180
176
.setDatanodeUuid (UUID .randomUUID ().toString ()).build ());
181
177
}
182
178
@@ -198,6 +194,16 @@ public final void assertResults(boolean failWithException, AtomicReference<Throw
198
194
}
199
195
}
200
196
197
+ public final void setUpLogProtoReturn (ContainerStateMachine .Context context , int containerId , int localId ) {
198
+ when (context .getLogProto ()).thenReturn (ContainerProtos .ContainerCommandRequestProto .newBuilder ()
199
+ .setCmdType (ContainerProtos .Type .WriteChunk ).setWriteChunk (
200
+ ContainerProtos .WriteChunkRequestProto .newBuilder ().setBlockID (
201
+ ContainerProtos .DatanodeBlockID .newBuilder ().
202
+ setContainerID (containerId ).setLocalID (localId ).build ()).build ())
203
+ .setContainerID (containerId )
204
+ .setDatanodeUuid (UUID .randomUUID ().toString ()).build ());
205
+ }
206
+
201
207
@ ParameterizedTest
202
208
@ ValueSource (booleans = {true , false })
203
209
public void testApplyTransactionFailure (boolean failWithException ) throws ExecutionException ,
@@ -212,12 +218,7 @@ public void testApplyTransactionFailure(boolean failWithException) throws Execut
212
218
213
219
setUpMockDispatcherReturn (failWithException );
214
220
// Failing apply transaction on congtainer 1.
215
- when (context .getLogProto ()).thenReturn (ContainerProtos .ContainerCommandRequestProto .newBuilder ()
216
- .setCmdType (ContainerProtos .Type .WriteChunk ).setWriteChunk (
217
- ContainerProtos .WriteChunkRequestProto .newBuilder ().setBlockID (
218
- ContainerProtos .DatanodeBlockID .newBuilder ().setContainerID (1 ).setLocalID (1 ).build ()).build ())
219
- .setContainerID (1 )
220
- .setDatanodeUuid (UUID .randomUUID ().toString ()).build ());
221
+ setUpLogProtoReturn (context , 1 , 1 );
221
222
AtomicReference <Throwable > throwable = new AtomicReference <>(null );
222
223
Function <Throwable , ? extends Message > throwableSetter = getThrowableSetter (throwable );
223
224
//apply transaction will fail because of runtime exception thrown by dispatcher, which marks the first
@@ -238,13 +239,7 @@ public void testApplyTransactionFailure(boolean failWithException) throws Execut
238
239
239
240
// Another apply transaction on a different container 2 shouldn't fail because the previous apply transaction
240
241
// failure was only on container 1.
241
- when (context .getLogProto ()).thenReturn (ContainerProtos .ContainerCommandRequestProto .newBuilder ()
242
- .setCmdType (ContainerProtos .Type .WriteChunk ).setWriteChunk (
243
- ContainerProtos .WriteChunkRequestProto .newBuilder ().setBlockID (
244
- ContainerProtos .DatanodeBlockID .newBuilder ().setContainerID (2 ).setLocalID (1 ).build ()).build ())
245
- .setContainerID (2 )
246
- .setDatanodeUuid (UUID .randomUUID ().toString ()).build ());
247
-
242
+ setUpLogProtoReturn (context , 2 , 1 );
248
243
reset (dispatcher );
249
244
throwable .set (null );
250
245
when (dispatcher .dispatch (any (), any ())).thenReturn (ContainerProtos .ContainerCommandResponseProto
@@ -280,7 +275,7 @@ public void testWriteTimout() throws Exception {
280
275
return null ;
281
276
}).when (dispatcher ).dispatch (any (), any ());
282
277
283
- setUpMockRequestProto (context );
278
+ setUpMockRequestProtoReturn (context , "Test data" , 1 , 1 );
284
279
AtomicReference <Throwable > throwable = new AtomicReference <>(null );
285
280
Function <Throwable , ? extends Message > throwableSetter = t -> {
286
281
throwable .set (t );
0 commit comments