2 * Copyright (c) 2015 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
9 package org.opendaylight.controller.cluster.datastore;
11 import static org.junit.Assert.fail;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.never;
14 import static org.mockito.Mockito.verify;
15 import com.codahale.metrics.Snapshot;
16 import com.codahale.metrics.Timer;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
23 public class TransactionRateLimitingCommitCallbackTest {
25 public ActorContext actorContext;
28 public DatastoreContext datastoreContext;
31 public Timer commitTimer;
34 private Timer.Context commitTimerContext;
37 private Snapshot commitSnapshot;
41 MockitoAnnotations.initMocks(this);
42 doReturn(datastoreContext).when(actorContext).getDatastoreContext();
43 doReturn(30).when(datastoreContext).getShardTransactionCommitTimeoutInSeconds();
44 doReturn(commitTimer).when(actorContext).getOperationTimer("commit");
45 doReturn(commitTimerContext).when(commitTimer).time();
46 doReturn(commitSnapshot).when(commitTimer).getSnapshot();
50 public void testSuccess(){
51 TransactionRateLimitingCallback commitCallback = new TransactionRateLimitingCallback(actorContext);
53 commitCallback.success();
55 verify(commitTimerContext).stop();
59 public void testSuccessWithoutRun(){
60 TransactionRateLimitingCallback commitCallback = new TransactionRateLimitingCallback(actorContext);
63 commitCallback.success();
64 fail("Expected IllegalStateException");
65 } catch(IllegalStateException e){
68 verify(commitTimerContext, never()).stop();
73 public void testFailure(){
74 TransactionRateLimitingCallback commitCallback = new TransactionRateLimitingCallback(actorContext);
76 commitCallback.failure();
78 verify(commitTimerContext, never()).stop();