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.controller.cluster.datastore;
10 import java.util.concurrent.CompletionStage;
11 import java.util.concurrent.atomic.AtomicLong;
12 import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
13 import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
14 import org.opendaylight.controller.cluster.access.concepts.FrontendType;
15 import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
16 import org.opendaylight.controller.cluster.access.concepts.MemberName;
17 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
18 import scala.compat.java8.FutureConverters;
19 import scala.concurrent.Await;
20 import scala.concurrent.duration.Duration;
22 public abstract class AbstractTest {
23 protected static final MemberName MEMBER_NAME = MemberName.forName("member-1");
24 protected static final MemberName MEMBER_2_NAME = MemberName.forName("member-2");
26 private static final FrontendType FRONTEND_TYPE = FrontendType.forName(ShardTransactionTest.class.getSimpleName());
28 protected static final FrontendIdentifier FRONTEND_ID = FrontendIdentifier.create(MEMBER_NAME, FRONTEND_TYPE);
30 private static final ClientIdentifier CLIENT_ID = ClientIdentifier.create(FRONTEND_ID, 0);
31 private static final LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(CLIENT_ID, 0);
32 private static final AtomicLong HISTORY_COUNTER = new AtomicLong();
33 private static final AtomicLong TX_COUNTER = new AtomicLong();
35 protected static void setUpStatic() {
36 HISTORY_COUNTER.set(1L);
40 protected static TransactionIdentifier nextTransactionId() {
41 return new TransactionIdentifier(HISTORY_ID, TX_COUNTER.getAndIncrement());
44 protected static LocalHistoryIdentifier nextHistoryId() {
45 return new LocalHistoryIdentifier(CLIENT_ID, HISTORY_COUNTER.incrementAndGet());
48 protected static <T> T waitOnAsyncTask(final CompletionStage<T> completionStage, final Duration timeout)
50 return Await.result(FutureConverters.toScala(completionStage), timeout);