rpcbenchmark: final parameters
[controller.git] / benchmark / rpcbenchmark / src / main / java / rpcbenchmark / impl / GlobalBindingRTCClient.java
1 /*
2  * Copyright (c) 2015 Cisco Systems and others.  All rights reserved.
3  *
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
7  */
8 package rpcbenchmark.impl;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.Future;
14 import java.util.concurrent.atomic.AtomicLong;
15
16 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
17 import org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.GlobalRpcBenchInput;
18 import org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.GlobalRpcBenchInputBuilder;
19 import org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.GlobalRpcBenchOutput;
20 import org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.RpcbenchPayloadService;
21 import org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.payload.Payload;
22 import org.opendaylight.yang.gen.v1.rpcbench.payload.rev150702.payload.PayloadBuilder;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.slf4j.Logger;
25 import org.slf4j.LoggerFactory;
26
27 public class GlobalBindingRTCClient implements RTCClient {
28
29     private static final Logger LOG = LoggerFactory.getLogger(GlobalBindingRTCClient.class);
30     private final RpcbenchPayloadService service;
31     private final AtomicLong rpcOk = new AtomicLong(0);
32     private final AtomicLong rpcError = new AtomicLong(0);
33     private final GlobalRpcBenchInput inVal;
34     private final int inSize;
35
36     public long getRpcOk() {
37         return rpcOk.get();
38     }
39
40     public long getRpcError() {
41         return rpcError.get();
42     }
43
44     public GlobalBindingRTCClient(final RpcConsumerRegistry registry, final int inSize) {
45         if (registry != null) {
46             this.service = registry.getRpcService(RpcbenchPayloadService.class);
47         } else {
48             this.service = null;
49         }
50
51         this.inSize = inSize;
52         List<Payload> listVals = new ArrayList<>();
53         for (int i = 0; i < inSize; i++) {
54             listVals.add(new PayloadBuilder().setId(i).build());
55         }
56         inVal = new GlobalRpcBenchInputBuilder().setPayload(listVals).build();
57     }
58
59     public void runTest(final int iterations) {
60         int rpcOk = 0;
61         int rpcError = 0;
62
63         for (int i = 0; i < iterations; i++) {
64             Future<RpcResult<GlobalRpcBenchOutput>> output = service.globalRpcBench(inVal);
65             try {
66                 RpcResult<GlobalRpcBenchOutput> rpcResult = output.get();
67
68                 if (rpcResult.isSuccessful()) {
69                     List<Payload> retVal = rpcResult.getResult().getPayload();
70                     if (retVal.size() == inSize) {
71                         rpcOk++;
72                     }
73                     else {
74                         rpcError++;
75                     }
76                 }
77             } catch (InterruptedException | ExecutionException e) {
78                 rpcError++;
79                 LOG.error("Execution failed: ", e);
80             }
81         }
82
83         this.rpcOk.addAndGet(rpcOk);
84         this.rpcError.addAndGet(rpcError);
85     }
86
87     @Override
88     public void close() {
89         // TODO Auto-generated method stub
90
91     }
92
93 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.