import com.google.common.base.Stopwatch;
import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import java.util.Collection;
import java.util.concurrent.Future;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.Cars;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.CarsBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.RegisterOwnershipInput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StopStressTestOutput;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StopStressTestOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.StressTestInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.UnregisterOwnershipInput;
import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.config.sal.clustering.it.car.rev140818.cars.CarEntry;
private static final String ENTITY_TYPE = "cars";
+ private AtomicLong succcessCounter = new AtomicLong();
+ private AtomicLong failureCounter = new AtomicLong();
+
private final CarEntityOwnershipListener ownershipListener = new CarEntityOwnershipListener();
private final AtomicBoolean registeredListener = new AtomicBoolean();
if ((input.getRate() == null) || (input.getRate() == 0)) {
log.info("Exiting stress test as no rate is given.");
return Futures.immediateFuture(RpcResultBuilder.<Void>failed()
- .withError(ErrorType.PROTOCOL, "invalid rate")
- .build());
+ .withError(ErrorType.PROTOCOL, "invalid rate")
+ .build());
} else {
inputRate = input.getRate();
}
log.info("Stress test starting : rate: {} count: {}", inputRate, inputCount);
stopThread();
+ // clear counters
+ succcessCounter.set(0);
+ failureCounter.set(0);
WriteTransaction tx = dataProvider.newWriteOnlyTransaction();
InstanceIdentifier<Cars> carsId = InstanceIdentifier.<Cars>builder(Cars.class).build();
tx.put(LogicalDatastoreType.CONFIGURATION,
InstanceIdentifier.<Cars>builder(Cars.class).child(CarEntry.class, car.getKey()).build(),
car);
- tx.submit();
+ CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit();
+ Futures.addCallback(future, new FutureCallback<Void>() {
+
+ @Override
+ public void onSuccess(final Void result) {
+ // Transaction succeeded
+ succcessCounter.getAndIncrement();
+ }
+
+ @Override
+ public void onFailure(final Throwable t) {
+ // Transaction failed
+ failureCounter.getAndIncrement();
+ LOG.error("Put Cars failed", t);
+ }
+ });
try {
TimeUnit.NANOSECONDS.sleep(sleep);
} catch (InterruptedException e) {
}
@Override
- public Future<RpcResult<Void>> stopStressTest() {
+ public Future<RpcResult<StopStressTestOutput>> stopStressTest() {
stopThread();
- return Futures.immediateFuture(RpcResultBuilder.<Void>success().build());
+ StopStressTestOutputBuilder stopStressTestOutput;
+ stopStressTestOutput = new StopStressTestOutputBuilder()
+ .setSuccessCount(succcessCounter.longValue())
+ .setFailureCount(failureCounter.longValue());
+
+ StopStressTestOutput result = stopStressTestOutput.build();
+ log.info("Executed Stop Stress test; No. of cars created {}; " +
+ "No. of cars failed {}; ", succcessCounter, failureCounter);
+ // clear counters
+ succcessCounter.set(0);
+ failureCounter.set(0);
+ return Futures.immediateFuture(RpcResultBuilder.<StopStressTestOutput>success(result).build());
}