2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.openflowplugin.impl.util;
10 import com.google.common.collect.Lists;
11 import java.util.ArrayList;
12 import java.util.EnumSet;
13 import java.util.List;
14 import org.junit.Assert;
15 import org.junit.Test;
16 import org.opendaylight.openflowplugin.impl.services.batch.BatchPlanStep;
17 import org.opendaylight.openflowplugin.impl.services.batch.BatchStepType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutput;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.ProcessFlatBatchOutputBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.Batch;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.BatchBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.BatchChoice;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddFlowCaseBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddGroupCaseBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchAddMeterCaseBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchRemoveFlowCaseBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchRemoveGroupCaseBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchRemoveMeterCaseBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchUpdateFlowCaseBuilder;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchUpdateGroupCaseBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.FlatBatchUpdateMeterCaseBuilder;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.flow._case.FlatBatchAddFlow;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.flow._case.FlatBatchAddFlowBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.flow._case.FlatBatchAddFlowKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.group._case.FlatBatchAddGroup;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.group._case.FlatBatchAddGroupBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.group._case.FlatBatchAddGroupKey;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.meter._case.FlatBatchAddMeter;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.meter._case.FlatBatchAddMeterBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.add.meter._case.FlatBatchAddMeterKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.flow._case.FlatBatchRemoveFlow;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.flow._case.FlatBatchRemoveFlowBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.flow._case.FlatBatchRemoveFlowKey;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.group._case.FlatBatchRemoveGroup;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.group._case.FlatBatchRemoveGroupBuilder;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.group._case.FlatBatchRemoveGroupKey;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.meter._case.FlatBatchRemoveMeter;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.meter._case.FlatBatchRemoveMeterBuilder;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.remove.meter._case.FlatBatchRemoveMeterKey;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.flow._case.FlatBatchUpdateFlow;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.flow._case.FlatBatchUpdateFlowBuilder;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.flow._case.FlatBatchUpdateFlowKey;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.group._case.FlatBatchUpdateGroup;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.group._case.FlatBatchUpdateGroupBuilder;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.group._case.FlatBatchUpdateGroupKey;
56 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.meter._case.FlatBatchUpdateMeter;
57 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.meter._case.FlatBatchUpdateMeterBuilder;
58 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.input.batch.batch.choice.flat.batch.update.meter._case.FlatBatchUpdateMeterKey;
59 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailure;
60 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailureBuilder;
61 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.BatchFailureKey;
62 import org.opendaylight.yang.gen.v1.urn.opendaylight.flat.batch.service.rev160321.process.flat.batch.output.batch.failure.batch.item.id.choice.FlatBatchFailureFlowIdCaseBuilder;
63 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
64 import org.opendaylight.yangtools.yang.common.RpcError;
65 import org.opendaylight.yangtools.yang.common.RpcResult;
66 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
67 import org.opendaylight.yangtools.yang.common.Uint16;
68 import org.slf4j.Logger;
69 import org.slf4j.LoggerFactory;
72 * Test for {@link FlatBatchUtil}.
74 public class FlatBatchUtilTest {
76 private static final Logger LOG = LoggerFactory.getLogger(FlatBatchUtilTest.class);
79 public void testMarkBarriersWhereNeeded_noBarrier() {
80 final List<Batch> batches = Lists.newArrayList(
81 //general part - no flush required
82 createBatch(BatchStepType.GROUP_REMOVE),
83 createBatch(BatchStepType.METER_REMOVE),
84 createBatch(BatchStepType.FLOW_ADD),
85 createBatch(BatchStepType.FLOW_REMOVE, 2),
86 createBatch(BatchStepType.FLOW_ADD),
87 createBatch(BatchStepType.FLOW_UPDATE),
88 createBatch(BatchStepType.GROUP_ADD),
89 createBatch(BatchStepType.GROUP_UPDATE),
90 createBatch(BatchStepType.METER_ADD),
91 createBatch(BatchStepType.METER_UPDATE)
94 final List<BatchPlanStep> batchPlan = FlatBatchUtil.assembleBatchPlan(batches);
95 FlatBatchUtil.markBarriersWhereNeeded(batchPlan);
97 Assert.assertEquals(10, batchPlan.size());
98 for (int i = 0; i < batchPlan.size(); i++) {
99 final BatchPlanStep planStep = batchPlan.get(i);
100 final boolean barrierBefore = planStep.isBarrierAfter();
101 LOG.debug("checking barrier mark @ {} {} -> {}",
102 i, planStep.getStepType(), barrierBefore);
104 Assert.assertFalse(barrierBefore);
109 public void testMarkBarriersWhereNeeded_allBarriers() {
110 // need to flush G+/F+
111 checkBarriersBetween(BatchStepType.GROUP_ADD, BatchStepType.FLOW_ADD);
112 // need to flush G+/F*
113 checkBarriersBetween(BatchStepType.GROUP_ADD, BatchStepType.FLOW_UPDATE);
114 // need to flush F-/G-
115 checkBarriersBetween(BatchStepType.FLOW_REMOVE, BatchStepType.GROUP_REMOVE);
116 // need to flush F*/G-
117 checkBarriersBetween(BatchStepType.FLOW_UPDATE, BatchStepType.GROUP_REMOVE);
119 // need to flush G+/G+
120 checkBarriersBetween(BatchStepType.GROUP_ADD, BatchStepType.GROUP_ADD);
121 // need to flush G-/G-
122 checkBarriersBetween(BatchStepType.GROUP_REMOVE, BatchStepType.GROUP_REMOVE);
123 // need to flush G*/G+
124 checkBarriersBetween(BatchStepType.GROUP_UPDATE, BatchStepType.GROUP_ADD);
125 // need to flush G*/G-
126 checkBarriersBetween(BatchStepType.GROUP_UPDATE, BatchStepType.GROUP_REMOVE);
128 // need to flush M+/F+
129 checkBarriersBetween(BatchStepType.METER_ADD, BatchStepType.FLOW_ADD);
130 // need to flush M+/F*
131 checkBarriersBetween(BatchStepType.METER_ADD, BatchStepType.FLOW_UPDATE);
132 // need to flush F-/M-
133 checkBarriersBetween(BatchStepType.FLOW_REMOVE, BatchStepType.METER_REMOVE);
134 // need to flush F*/M-
135 checkBarriersBetween(BatchStepType.FLOW_UPDATE, BatchStepType.METER_REMOVE);
138 private void checkBarriersBetween(final BatchStepType typeOfFirst, final BatchStepType typeOfSecond) {
139 final List<Batch> batches = Lists.newArrayList(createBatch(typeOfFirst), createBatch(typeOfSecond));
140 final List<BatchPlanStep> batchPlan = FlatBatchUtil.assembleBatchPlan(batches);
141 FlatBatchUtil.markBarriersWhereNeeded(batchPlan);
142 LOG.debug("checking barrier between {} / {}", typeOfFirst, typeOfSecond);
143 Assert.assertEquals(2, batchPlan.size());
144 Assert.assertTrue("barrier expected between "
145 + typeOfFirst + " / "
146 + typeOfSecond, batchPlan.get(0).isBarrierAfter());
147 Assert.assertFalse(batchPlan.get(1).isBarrierAfter());
151 public void testMarkBarriersWhereNeeded_single() {
152 final List<Batch> batches = Lists.newArrayList(
153 //general part - no flush required
154 createBatch(BatchStepType.GROUP_REMOVE)
157 final List<BatchPlanStep> batchPlan = FlatBatchUtil.assembleBatchPlan(batches);
158 FlatBatchUtil.markBarriersWhereNeeded(batchPlan);
160 Assert.assertEquals(1, batchPlan.size());
161 Assert.assertFalse(batchPlan.get(0).isBarrierAfter());
165 public void testDecideBarrier() {
166 Assert.assertTrue(FlatBatchUtil.decideBarrier(EnumSet.of(BatchStepType.GROUP_ADD), BatchStepType.FLOW_ADD));
167 Assert.assertTrue(FlatBatchUtil.decideBarrier(EnumSet.of(BatchStepType.GROUP_ADD), BatchStepType.FLOW_UPDATE));
169 Assert.assertTrue(FlatBatchUtil
170 .decideBarrier(EnumSet.of(BatchStepType.FLOW_REMOVE), BatchStepType.GROUP_REMOVE));
171 Assert.assertTrue(FlatBatchUtil
172 .decideBarrier(EnumSet.of(BatchStepType.FLOW_UPDATE), BatchStepType.GROUP_REMOVE));
174 Assert.assertTrue(FlatBatchUtil.decideBarrier(EnumSet.of(BatchStepType.METER_ADD), BatchStepType.FLOW_ADD));
175 Assert.assertTrue(FlatBatchUtil.decideBarrier(EnumSet.of(BatchStepType.METER_ADD), BatchStepType.FLOW_UPDATE));
177 Assert.assertTrue(FlatBatchUtil
178 .decideBarrier(EnumSet.of(BatchStepType.FLOW_REMOVE), BatchStepType.METER_REMOVE));
179 Assert.assertTrue(FlatBatchUtil
180 .decideBarrier(EnumSet.of(BatchStepType.FLOW_UPDATE), BatchStepType.METER_REMOVE));
184 public void testAssembleBatchPlan() {
185 final List<Batch> batches = Lists.newArrayList(
186 createBatch(BatchStepType.GROUP_ADD),
187 createBatch(BatchStepType.GROUP_REMOVE, 2),
188 createBatch(BatchStepType.GROUP_REMOVE),
189 createBatch(BatchStepType.GROUP_ADD),
190 createBatch(BatchStepType.GROUP_UPDATE, 3)
193 final List<BatchPlanStep> batchPlanSteps = FlatBatchUtil.assembleBatchPlan(batches);
194 Assert.assertEquals(5, batchPlanSteps.size());
197 checkSegment(batchPlanSteps.get(index++), BatchStepType.GROUP_ADD, 1);
198 checkSegment(batchPlanSteps.get(index++), BatchStepType.GROUP_REMOVE, 2);
199 checkSegment(batchPlanSteps.get(index++), BatchStepType.GROUP_REMOVE, 1);
200 checkSegment(batchPlanSteps.get(index++), BatchStepType.GROUP_ADD, 1);
201 checkSegment(batchPlanSteps.get(index++), BatchStepType.GROUP_UPDATE, 3);
204 private static void checkSegment(final BatchPlanStep planStep, final BatchStepType stepType, final int expected) {
205 Assert.assertEquals(stepType, planStep.getStepType());
206 Assert.assertEquals(expected, planStep.getTaskBag().size());
210 public void testDetectBatchStepType() {
211 for (BatchStepType stepType : BatchStepType.values()) {
212 LOG.debug("checking detection of: {}", stepType);
213 final Batch batch = createBatch(stepType);
214 final BatchStepType actualType = FlatBatchUtil.detectBatchStepType(batch.getBatchChoice());
215 Assert.assertEquals(stepType, actualType);
219 private static Batch createBatch(final BatchStepType type) {
220 return createBatch(type, 1);
223 private static Batch createBatch(final BatchStepType type, final int size) {
224 final BatchChoice batchCase;
227 batchCase = new FlatBatchAddFlowCaseBuilder()
228 .setFlatBatchAddFlow(repeatFlatBatchAddFlowIntoList(size))
232 batchCase = new FlatBatchRemoveFlowCaseBuilder()
233 .setFlatBatchRemoveFlow(repeatFlatBatchRemoveFlowIntoList(size))
237 batchCase = new FlatBatchUpdateFlowCaseBuilder()
238 .setFlatBatchUpdateFlow(repeatFlatBatchUpdateFlowIntoList(size))
242 batchCase = new FlatBatchAddGroupCaseBuilder()
243 .setFlatBatchAddGroup(repeatFlatBatchAddGroupIntoList(size))
247 batchCase = new FlatBatchRemoveGroupCaseBuilder()
248 .setFlatBatchRemoveGroup(repeatFlatBatchRemoveGroupIntoList(size))
252 batchCase = new FlatBatchUpdateGroupCaseBuilder()
253 .setFlatBatchUpdateGroup(repeatFlatBatchUpdateGroupIntoList(size))
257 batchCase = new FlatBatchAddMeterCaseBuilder()
258 .setFlatBatchAddMeter(repeatFlatBatchAddMeterIntoList(size))
262 batchCase = new FlatBatchRemoveMeterCaseBuilder()
263 .setFlatBatchRemoveMeter(repeatFlatBatchRemoveMeterIntoList(size))
267 batchCase = new FlatBatchUpdateMeterCaseBuilder()
268 .setFlatBatchUpdateMeter(repeatFlatBatchUpdateMeterIntoList(size))
272 LOG.warn("unsupported batch type: {}", type);
273 throw new IllegalArgumentException("unsupported batch type: " + type);
276 return new BatchBuilder()
277 .setBatchOrder(Uint16.ZERO)
278 .setBatchChoice(batchCase)
282 private static List<FlatBatchAddGroup> repeatFlatBatchAddGroupIntoList(final int size) {
283 final List<FlatBatchAddGroup> list = new ArrayList<>();
284 for (int i = 0; i < size; i++) {
285 list.add(new FlatBatchAddGroupBuilder().withKey(new FlatBatchAddGroupKey(Uint16.valueOf(i))).build());
290 private static List<FlatBatchUpdateGroup> repeatFlatBatchUpdateGroupIntoList(final int size) {
291 final List<FlatBatchUpdateGroup> list = new ArrayList<>();
292 for (int i = 0; i < size; i++) {
293 list.add(new FlatBatchUpdateGroupBuilder().withKey(new FlatBatchUpdateGroupKey(Uint16.valueOf(i))).build());
298 private static List<FlatBatchRemoveGroup> repeatFlatBatchRemoveGroupIntoList(final int size) {
299 final List<FlatBatchRemoveGroup> list = new ArrayList<>();
300 for (int i = 0; i < size; i++) {
301 list.add(new FlatBatchRemoveGroupBuilder().withKey(new FlatBatchRemoveGroupKey(Uint16.valueOf(i))).build());
306 private static List<FlatBatchAddFlow> repeatFlatBatchAddFlowIntoList(final int size) {
307 final List<FlatBatchAddFlow> list = new ArrayList<>();
308 for (int i = 0; i < size; i++) {
309 list.add(new FlatBatchAddFlowBuilder().withKey(new FlatBatchAddFlowKey(Uint16.valueOf(i))).build());
314 private static List<FlatBatchUpdateFlow> repeatFlatBatchUpdateFlowIntoList(final int size) {
315 final List<FlatBatchUpdateFlow> list = new ArrayList<>();
316 for (int i = 0; i < size; i++) {
317 list.add(new FlatBatchUpdateFlowBuilder().withKey(new FlatBatchUpdateFlowKey(Uint16.valueOf(i))).build());
322 private static List<FlatBatchRemoveFlow> repeatFlatBatchRemoveFlowIntoList(final int size) {
323 final List<FlatBatchRemoveFlow> list = new ArrayList<>();
324 for (int i = 0; i < size; i++) {
325 list.add(new FlatBatchRemoveFlowBuilder().withKey(new FlatBatchRemoveFlowKey(Uint16.valueOf(i))).build());
330 private static List<FlatBatchAddMeter> repeatFlatBatchAddMeterIntoList(final int size) {
331 final List<FlatBatchAddMeter> list = new ArrayList<>();
332 for (int i = 0; i < size; i++) {
333 list.add(new FlatBatchAddMeterBuilder().withKey(new FlatBatchAddMeterKey(Uint16.valueOf(i))).build());
338 private static List<FlatBatchUpdateMeter> repeatFlatBatchUpdateMeterIntoList(final int size) {
339 final List<FlatBatchUpdateMeter> list = new ArrayList<>();
340 for (int i = 0; i < size; i++) {
341 list.add(new FlatBatchUpdateMeterBuilder().withKey(new FlatBatchUpdateMeterKey(Uint16.valueOf(i))).build());
346 private static List<FlatBatchRemoveMeter> repeatFlatBatchRemoveMeterIntoList(final int size) {
347 final List<FlatBatchRemoveMeter> list = new ArrayList<>();
348 for (int i = 0; i < size; i++) {
349 list.add(new FlatBatchRemoveMeterBuilder().withKey(new FlatBatchRemoveMeterKey(Uint16.valueOf(i))).build());
355 public void testMergeJobsResultsFutures() {
356 final BatchFailure batchFailure = new BatchFailureBuilder()
357 .setBatchOrder(Uint16.valueOf(9))
358 .setBatchItemIdChoice(new FlatBatchFailureFlowIdCaseBuilder()
359 .setFlowId(new FlowId("11"))
361 .withKey(new BatchFailureKey(Uint16.ZERO))
363 final BatchFailure batchFailure_1 = new BatchFailureBuilder()
364 .setBatchOrder(Uint16.valueOf(9))
365 .setBatchItemIdChoice(new FlatBatchFailureFlowIdCaseBuilder()
366 .setFlowId(new FlowId("11"))
368 .withKey(new BatchFailureKey(Uint16.ONE))
371 final ProcessFlatBatchOutput output
372 = new ProcessFlatBatchOutputBuilder().setBatchFailure(Lists.newArrayList(batchFailure)).build();
374 final ProcessFlatBatchOutput output_1
375 = new ProcessFlatBatchOutputBuilder().setBatchFailure(Lists.newArrayList(batchFailure_1)).build();
377 final RpcResult<ProcessFlatBatchOutput> rpcResultFailed = RpcResultBuilder.<ProcessFlatBatchOutput>failed()
378 .withError(RpcError.ErrorType.APPLICATION, "ut-rpcError")
379 .withResult(output).build();
381 final RpcResult<ProcessFlatBatchOutput> rpcResultFailed_1 = RpcResultBuilder.<ProcessFlatBatchOutput>failed()
382 .withError(RpcError.ErrorType.APPLICATION, "ut-rpcError")
383 .withResult(output_1).build();
384 final RpcResult<ProcessFlatBatchOutput> rpcResultSuccess = RpcResultBuilder.<ProcessFlatBatchOutput>success()
385 .withResult(new ProcessFlatBatchOutputBuilder().setBatchFailure(new ArrayList<>())).build();
387 final RpcResult<ProcessFlatBatchOutput> rpcResult1
388 = FlatBatchUtil.mergeRpcResults().apply(Lists.newArrayList(rpcResultFailed, rpcResultSuccess));
389 Assert.assertEquals(1, rpcResult1.getErrors().size());
390 Assert.assertFalse(rpcResult1.isSuccessful());
392 final RpcResult<ProcessFlatBatchOutput> rpcResult2
393 = FlatBatchUtil.mergeRpcResults().apply(Lists.newArrayList(rpcResultFailed, rpcResultFailed_1));
394 Assert.assertEquals(2, rpcResult2.getErrors().size());
395 Assert.assertFalse(rpcResult2.isSuccessful());
397 final RpcResult<ProcessFlatBatchOutput> rpcResult3
398 = FlatBatchUtil.mergeRpcResults().apply(Lists.newArrayList(rpcResultSuccess, rpcResultSuccess));
399 Assert.assertEquals(0, rpcResult3.getErrors().size());
400 Assert.assertTrue(rpcResult3.isSuccessful());