final String jspFilter = "jspFilter";
final String exactMatch = "/somePath";
final String prefixFilter = "prefixFilter";
- LinkedHashMap<String, String> patternMap = new LinkedHashMap<String, String>() {
- {
- put(exactMatch, exactMatchFilter);
- put("/*", defaultFilter);
- put("*.jsp", jspFilter);
- put("/foo/*", prefixFilter);
- }
- };
+ LinkedHashMap<String, String> patternMap = new LinkedHashMap<>();
+ patternMap.put(exactMatch, exactMatchFilter);
+ patternMap.put("/*", defaultFilter);
+ patternMap.put("*.jsp", jspFilter);
+ patternMap.put("/foo/*", prefixFilter);
urlMatcher = new UrlMatcher<>(patternMap);
assertMatches("/abc", defaultFilter);
assertMatches(exactMatch, exactMatchFilter, defaultFilter);
Object serviceTypeRaw = args[0];
Object serviceInstance = args[1];
- Dictionary<String, ?> props = (Dictionary) args[2];
+ Dictionary<String, ?> props = (Dictionary<String, ?>) args[2];
if (serviceTypeRaw instanceof Class) {
Class<?> serviceType = (Class<?>) serviceTypeRaw;
import org.opendaylight.controller.config.persist.api.PropertiesProvider;
public class PropertiesProviderTest implements PropertiesProvider {
- private final Map<String,String> properties = new HashMap();
+ private final Map<String,String> properties = new HashMap<>();
public void addProperty(String key,String value){
properties.put(key,value);
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
-import org.opendaylight.yangtools.yang.binding.DataObject;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.InstanceIdentifierBuilder;
import org.slf4j.Logger;
InstanceIdentifierBuilder<Node> builder = ((InstanceIdentifier<Node>) ref.getValue()).builder();
InstanceIdentifierBuilder<FlowCapableNode> augmentation = builder.augmentation(FlowCapableNode.class);
final InstanceIdentifier<FlowCapableNode> path = augmentation.build();
- CheckedFuture readFuture = tx.read(LogicalDatastoreType.OPERATIONAL, path);
- Futures.addCallback(readFuture, new FutureCallback<Optional<? extends DataObject>>() {
+ CheckedFuture<Optional<FlowCapableNode>, ?> readFuture = tx.read(LogicalDatastoreType.OPERATIONAL, path);
+ Futures.addCallback(readFuture, new FutureCallback<Optional<FlowCapableNode>>() {
@Override
- public void onSuccess(Optional<? extends DataObject> optional) {
+ public void onSuccess(Optional<FlowCapableNode> optional) {
enqueueWriteNodeDataTx(node, flowNode, path);
if (!optional.isPresent()) {
enqueuePutTable0Tx(ref);
@Override protected void applySnapshot(final ByteString snapshot) {
state.clear();
try {
- state.putAll((HashMap) toObject(snapshot));
+ state.putAll((Map<String, String>) toObject(snapshot));
} catch (Exception e) {
LOG.error(e, "Exception in applying snapshot");
}
if(LOG.isDebugEnabled()) {
- LOG.debug("Snapshot applied to state : {}", ((HashMap) state).size());
+ LOG.debug("Snapshot applied to state : {}", ((Map<?, ?>) state).size());
}
}
public class Leader extends AbstractRaftActorBehavior {
- protected final Map<String, FollowerLogInformation> followerToLog = new HashMap();
+ protected final Map<String, FollowerLogInformation> followerToLog = new HashMap<>();
protected final Map<String, FollowerToSnapshot> mapFollowerToSnapshot = new HashMap<>();
private final Set<String> followers;
*/
public class AppendEntries extends AbstractRaftRPC {
- public static final Class SERIALIZABLE_CLASS = AppendEntriesMessages.AppendEntries.class;
+ public static final Class<AppendEntriesMessages.AppendEntries> SERIALIZABLE_CLASS = AppendEntriesMessages.AppendEntries.class;
private static final org.slf4j.Logger LOG = org.slf4j.LoggerFactory.getLogger(AppendEntries.class);
public class InstallSnapshot extends AbstractRaftRPC {
- public static final Class SERIALIZABLE_CLASS = InstallSnapshotMessages.InstallSnapshot.class;
+ public static final Class<InstallSnapshotMessages.InstallSnapshot> SERIALIZABLE_CLASS = InstallSnapshotMessages.InstallSnapshot.class;
private final String leaderId;
private final long lastIncludedIndex;
private long lastApplied = 0;
private final ElectionTerm electionTerm;
private ReplicatedLog replicatedLog;
- private Map<String, String> peerAddresses = new HashMap();
+ private Map<String, String> peerAddresses = new HashMap<>();
private ConfigParams configParams;
public MockRaftActorContext(){
Object data = toObject(snapshot);
System.out.println("!!!!!applyRecoverySnapshot: "+data);
if (data instanceof List) {
- state.addAll((List) data);
+ state.addAll((List<?>) data);
}
} catch (Exception e) {
e.printStackTrace();
return raftActor;
}
- public boolean waitForLogMessage(final Class logEventClass, String message){
+ public boolean waitForLogMessage(final Class<?> logEventClass, String message){
// Wait for a specific log message to show up
return
new JavaTestKit.EventFilter<Boolean>(logEventClass
MockRaftActorContext actorContext = (MockRaftActorContext) createActorContext();
- Map<String, String> peerAddresses = new HashMap();
+ Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put(followerActor.path().toString(),
followerActor.path().toString());
MockRaftActorContext actorContext =
(MockRaftActorContext) createActorContext();
- Map<String, String> peerAddresses = new HashMap();
+ Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put(followerActor.path().toString(),
followerActor.path().toString());
new JavaTestKit(getSystem()) {{
ActorRef followerActor = getSystem().actorOf(Props.create(MessageCollectorActor.class));
- Map<String, String> peerAddresses = new HashMap();
+ Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put(followerActor.path().toString(),
followerActor.path().toString());
ActorRef followerActor = getTestActor();
- Map<String, String> peerAddresses = new HashMap();
+ Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put(followerActor.path().toString(),
followerActor.path().toString());
ActorRef followerActor = getTestActor();
- Map<String, String> peerAddresses = new HashMap();
+ Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put(followerActor.path().toString(),
followerActor.path().toString());
ActorRef followerActor = getTestActor();
- Map<String, String> peerAddresses = new HashMap();
+ Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put(followerActor.path().toString(),
followerActor.path().toString());
ActorRef followerActor = getTestActor();
- Map<String, String> peerAddresses = new HashMap();
+ Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put(followerActor.path().toString(),
followerActor.path().toString());
ForwardMessageToBehaviorActor.setBehavior(follower);
- Map<String, String> peerAddresses = new HashMap();
+ Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put(followerActor.path().toString(),
followerActor.path().toString());
ForwardMessageToBehaviorActor.setBehavior(follower);
- Map<String, String> peerAddresses = new HashMap();
+ Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put(followerActor.path().toString(),
followerActor.path().toString());
MockRaftActorContext leaderActorContext =
new MockRaftActorContext("leader", getSystem(), leaderActor);
- Map<String, String> peerAddresses = new HashMap();
+ Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put("follower-1",
followerActor.path().toString());
leaderActorContext.setReplicatedLog(
new MockRaftActorContext.MockReplicatedLogBuilder().createEntries(0, 3, 1).build());
- Map<String, String> peerAddresses = new HashMap();
+ Map<String, String> peerAddresses = new HashMap<>();
peerAddresses.put("follower-1",
followerActor.path().toString());
* @param clazz
* @return
*/
- public static Object getFirstMatching(ActorRef actor, Class clazz) throws Exception {
+ public static Object getFirstMatching(ActorRef actor, Class<?> clazz) throws Exception {
List<Object> allMessages = getAllMessages(actor);
for(Object message : allMessages){
return null;
}
- public static List<Object> getAllMatching(ActorRef actor, Class clazz) throws Exception {
+ public static List<Object> getAllMatching(ActorRef actor, Class<?> clazz) throws Exception {
List<Object> allMessages = getAllMessages(actor);
List<Object> output = Lists.newArrayList();
if (path.isWildcarded()) {
return Optional.absent();
}
- return (Optional) getCodec().deserializeFunction(path).apply(Optional.<NormalizedNode<?, ?>> of(data));
+ return (Optional<DataObject>) getCodec().deserializeFunction(path).apply(Optional.<NormalizedNode<?, ?>> of(data));
}
private class TranslatingDataChangeInvoker implements DOMDataChangeListener {
return; //there's no actor to monitor
}
String actorName = owner.get().path().toStringWithoutAddress();
- String metricName = registry.name(actorName, QUEUE_SIZE);
+ String metricName = MetricRegistry.name(actorName, QUEUE_SIZE);
if (registry.getMetrics().containsKey(metricName))
return; //already registered
builder.setInstanceIdentifierValue(
InstanceIdentifierUtils.toSerializable((YangInstanceIdentifier) value, context));
} else if(value instanceof Set) {
- Set set = (Set) value;
+ Set<?> set = (Set<?>) value;
if (!set.isEmpty()) {
for (Object o : set) {
if (o instanceof String) {
return InstanceIdentifierUtils.fromSerializable(
node.getInstanceIdentifierValue(), context);
} else if(node.getIntValueType() == ValueType.BITS_TYPE.ordinal()){
- return new HashSet(node.getBitsValueList());
+ return new HashSet<>(node.getBitsValueList());
} else if(node.getIntValueType() == ValueType.BINARY_TYPE.ordinal()){
return node.getBytesValue().toByteArray();
}
BIG_DECIMAL_TYPE,
BINARY_TYPE;
- private static Map<Class, ValueType> types = new HashMap<>();
+ private static Map<Class<?>, ValueType> types = new HashMap<>();
static {
types.put(String.class, STRING_TYPE);
}
}
- private void writeObjSet(Set set) throws IOException {
+ private void writeObjSet(Set<?> set) throws IOException {
if(!set.isEmpty()){
writer.writeInt(set.size());
for(Object o : set){
writer.writeShort((Short) value);
break;
case ValueTypes.BITS_TYPE:
- writeObjSet((Set) value);
+ writeObjSet((Set<?>) value);
break;
case ValueTypes.YANG_IDENTIFIER_TYPE:
writeYangInstanceIdentifier((YangInstanceIdentifier) value);
public static final byte BIG_INTEGER_TYPE = 10;
public static final byte BIG_DECIMAL_TYPE = 11;
- private static Map<Class, Byte> types = new HashMap<>();
+ private static Map<Class<?>, Byte> types = new HashMap<>();
static {
types.put(String.class, Byte.valueOf(STRING_TYPE));
package org.opendaylight.controller.cluster.datastore.node.utils;
+import com.google.common.collect.ImmutableSet;
import org.junit.Test;
import org.opendaylight.controller.cluster.datastore.util.TestModel;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
import java.util.Set;
-
import static junit.framework.TestCase.assertEquals;
public class PathUtilsTest {
}
private YangInstanceIdentifier.AugmentationIdentifier augmentationIdentifier(){
- Set<QName> childNames = new HashSet();
- childNames.add(QNameFactory.create("(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics"));
+ Set<QName> childNames = ImmutableSet.of(QNameFactory.create("(urn:opendaylight:flow:table:statistics?revision=2013-12-15)flow-table-statistics"));
return new YangInstanceIdentifier.AugmentationIdentifier(childNames);
}
nodeBuilder.build());
assertTrue(o instanceof Set);
- assertTrue(((Set)o).contains("foo"));
- assertTrue(((Set) o).contains("bar"));
+ assertTrue(((Set<?>)o).contains("foo"));
+ assertTrue(((Set<?>) o).contains("bar"));
}
package org.opendaylight.controller.cluster.datastore.util;
+import com.google.common.collect.ImmutableSet;
import org.junit.Assert;
import org.junit.Test;
import org.opendaylight.controller.cluster.datastore.node.utils.serialization.QNameDeSerializationContext;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import java.util.ArrayList;
import java.util.Arrays;
-import java.util.HashSet;
import java.util.List;
public class InstanceIdentifierUtilsTest {
@Test
public void testAugmentationIdentifier() {
- YangInstanceIdentifier.PathArgument p1 = new YangInstanceIdentifier.AugmentationIdentifier(new HashSet(
- Arrays.asList(TEST_QNAME)));
+ YangInstanceIdentifier.PathArgument p1 = new YangInstanceIdentifier.AugmentationIdentifier(
+ ImmutableSet.of(TEST_QNAME));
List<YangInstanceIdentifier.PathArgument> arguments = new ArrayList<>();
import akka.actor.ActorSelection;
import akka.dispatch.OnComplete;
import com.google.common.base.Preconditions;
-import java.util.AbstractMap.SimpleEntry;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;
-import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import org.opendaylight.controller.cluster.datastore.messages.CloseTransactionChain;
import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
import org.opendaylight.controller.md.sal.common.api.data.TransactionChainClosedException;
private interface State {
boolean isReady();
- SimpleEntry<Object, List<Future<ActorSelection>>> getReadyFutures();
-
- void setReadyFutures(Object txIdentifier, List<Future<ActorSelection>> readyFutures);
+ List<Future<ActorSelection>> getPreviousReadyFutures();
}
private static class Allocated implements State {
- private volatile SimpleEntry<Object, List<Future<ActorSelection>>> readyFutures;
+ private final ChainedTransactionProxy transaction;
- @Override
- public boolean isReady() {
- return readyFutures != null;
+ Allocated(ChainedTransactionProxy transaction) {
+ this.transaction = transaction;
}
@Override
- public SimpleEntry<Object, List<Future<ActorSelection>>> getReadyFutures() {
- return readyFutures != null ? readyFutures : EMPTY_READY_FUTURES;
+ public boolean isReady() {
+ return transaction.isReady();
}
@Override
- public void setReadyFutures(Object txIdentifier, List<Future<ActorSelection>> readyFutures) {
- this.readyFutures = new SimpleEntry<>(txIdentifier, readyFutures);
+ public List<Future<ActorSelection>> getPreviousReadyFutures() {
+ return transaction.getReadyFutures();
}
}
private static abstract class AbstractDefaultState implements State {
@Override
- public SimpleEntry<Object, List<Future<ActorSelection>>> getReadyFutures() {
- return EMPTY_READY_FUTURES;
- }
-
- @Override
- public void setReadyFutures(Object txIdentifier, List<Future<ActorSelection>> readyFutures) {
- throw new IllegalStateException("No transaction is allocated");
+ public List<Future<ActorSelection>> getPreviousReadyFutures() {
+ return Collections.emptyList();
}
}
}
};
- private static final SimpleEntry<Object, List<Future<ActorSelection>>> EMPTY_READY_FUTURES =
- new SimpleEntry<Object, List<Future<ActorSelection>>>("",
- Collections.<Future<ActorSelection>>emptyList());
-
- private static final AtomicReferenceFieldUpdater<TransactionChainProxy, State> STATE_UPDATER =
- AtomicReferenceFieldUpdater.newUpdater(TransactionChainProxy.class, State.class, "state");
+ private static final AtomicInteger counter = new AtomicInteger(0);
private final ActorContext actorContext;
private final String transactionChainId;
- private volatile State state = IDLE_STATE;
- private static final AtomicInteger counter = new AtomicInteger(0);
+ private volatile State currentState = IDLE_STATE;
public TransactionChainProxy(ActorContext actorContext) {
this.actorContext = actorContext;
- transactionChainId = actorContext.getCurrentMemberName() + "-transaction-chain-" + counter.incrementAndGet();
+ transactionChainId = actorContext.getCurrentMemberName() + "-txn-chain-" + counter.incrementAndGet();
}
public String getTransactionChainId() {
@Override
public DOMStoreReadTransaction newReadOnlyTransaction() {
- checkReadyState();
- return new ChainedTransactionProxy(actorContext, TransactionProxy.TransactionType.READ_ONLY);
+ State localState = currentState;
+ checkReadyState(localState);
+
+ return new ChainedTransactionProxy(actorContext, TransactionProxy.TransactionType.READ_ONLY,
+ transactionChainId, localState.getPreviousReadyFutures());
}
@Override
@Override
public void close() {
- state = CLOSED_STATE;
+ currentState = CLOSED_STATE;
// Send a close transaction chain request to each and every shard
actorContext.broadcast(new CloseTransactionChain(transactionChainId));
}
private ChainedTransactionProxy allocateWriteTransaction(TransactionProxy.TransactionType type) {
- checkReadyState();
+ State localState = currentState;
+
+ checkReadyState(localState);
- ChainedTransactionProxy txProxy = new ChainedTransactionProxy(actorContext, type);
- STATE_UPDATER.compareAndSet(this, IDLE_STATE, new Allocated());
+ // Pass the ready Futures from the previous Tx.
+ ChainedTransactionProxy txProxy = new ChainedTransactionProxy(actorContext, type,
+ transactionChainId, localState.getPreviousReadyFutures());
+
+ currentState = new Allocated(txProxy);
return txProxy;
}
- private void checkReadyState() {
- Preconditions.checkState(state.isReady(), "Previous transaction %s is not ready yet",
- state.getReadyFutures().getKey());
+ private void checkReadyState(State state) {
+ Preconditions.checkState(state.isReady(), "Previous transaction is not ready yet");
}
- private class ChainedTransactionProxy extends TransactionProxy {
+ private static class ChainedTransactionProxy extends TransactionProxy {
+
+ /**
+ * Stores the ready Futures from the previous Tx in the chain.
+ */
+ private final List<Future<ActorSelection>> previousReadyFutures;
+
+ /**
+ * Stores the ready Futures from this transaction when it is readied.
+ */
+ private volatile List<Future<ActorSelection>> readyFutures;
- ChainedTransactionProxy(ActorContext actorContext, TransactionType transactionType) {
+ private ChainedTransactionProxy(ActorContext actorContext, TransactionType transactionType,
+ String transactionChainId, List<Future<ActorSelection>> previousReadyFutures) {
super(actorContext, transactionType, transactionChainId);
+ this.previousReadyFutures = previousReadyFutures;
+ }
+
+ List<Future<ActorSelection>> getReadyFutures() {
+ return readyFutures;
+ }
+
+ boolean isReady() {
+ return readyFutures != null;
}
@Override
protected void onTransactionReady(List<Future<ActorSelection>> readyFutures) {
- LOG.debug("onTransactionReady {} pending readyFutures size {} chain {}", getIdentifier(), readyFutures.size(), TransactionChainProxy.this.transactionChainId);
- state.setReadyFutures(getIdentifier(), readyFutures);
+ LOG.debug("onTransactionReady {} pending readyFutures size {} chain {}", getIdentifier(),
+ readyFutures.size(), getTransactionChainId());
+ this.readyFutures = readyFutures;
}
/**
final Object serializedCreateMessage) {
// Check if there are any previous ready Futures, otherwise let the super class handle it.
- // The second check is done to ensure the the previous ready Futures aren't for this
- // Tx instance as deadlock would occur if we tried to wait on our own Futures. This can
- // occur in this scenario:
- //
- // - the TransactionProxy is created and the client does a write.
- //
- // - the TransactionProxy then attempts to create the shard Tx. However it first
- // sends a FindPrimaryShard message to the shard manager to find the local shard
- // This call is done async.
- //
- // - the client submits the Tx and the TransactionProxy is readied and we cache
- // the ready Futures here.
- //
- // - then the FindPrimaryShard call completes and this method is called to create
- // the shard Tx. However the cached Futures were from the ready on this Tx. If we
- // tried to wait on them, it would cause a form of deadlock as the ready Future
- // would be waiting on the Tx create Future and vice versa.
- SimpleEntry<Object, List<Future<ActorSelection>>> readyFuturesEntry = state.getReadyFutures();
- List<Future<ActorSelection>> readyFutures = readyFuturesEntry.getValue();
- if(readyFutures.isEmpty() || getIdentifier().equals(readyFuturesEntry.getKey())) {
+ if(previousReadyFutures.isEmpty()) {
return super.sendCreateTransaction(shard, serializedCreateMessage);
}
// Combine the ready Futures into 1.
Future<Iterable<ActorSelection>> combinedFutures = akka.dispatch.Futures.sequence(
- readyFutures, actorContext.getActorSystem().dispatcher());
+ previousReadyFutures, getActorContext().getActorSystem().dispatcher());
// Add a callback for completion of the combined Futures.
final Promise<Object> createTxPromise = akka.dispatch.Futures.promise();
// A Ready Future failed so fail the returned Promise.
createTxPromise.failure(failure);
} else {
+ LOG.debug("Previous Tx readied - sending CreateTransaction for {} on chain {}",
+ getIdentifier(), getTransactionChainId());
+
// Send the CreateTx message and use the resulting Future to complete the
// returned Promise.
- createTxPromise.completeWith(actorContext.executeOperationAsync(shard,
+ createTxPromise.completeWith(getActorContext().executeOperationAsync(shard,
serializedCreateMessage));
}
}
};
- combinedFutures.onComplete(onComplete, actorContext.getActorSystem().dispatcher());
+ combinedFutures.onComplete(onComplete, getActorContext().getActorSystem().dispatcher());
return createTxPromise.future();
}
return transactionChainId;
}
+ protected ActorContext getActorContext() {
+ return actorContext;
+ }
+
/**
* Interface for a transaction operation to be invoked later.
*/
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Uninterruptibles;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
}};
}
+ @Test
+ public void testCreateChainedTransactionsInQuickSuccession() throws Exception{
+ new IntegrationTestKit(getSystem()) {{
+ DistributedDataStore dataStore = setupDistributedDataStore(
+ "testCreateChainedTransactionsInQuickSuccession", "test-1");
+
+ DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+
+ NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+
+ int nTxs = 20;
+ List<DOMStoreThreePhaseCommitCohort> cohorts = new ArrayList<>(nTxs);
+ for(int i = 0; i < nTxs; i++) {
+ DOMStoreReadWriteTransaction rwTx = txChain.newReadWriteTransaction();
+
+ rwTx.merge(TestModel.TEST_PATH, testNode);
+
+ cohorts.add(rwTx.ready());
+
+ }
+
+ for(DOMStoreThreePhaseCommitCohort cohort: cohorts) {
+ doCommit(cohort);
+ }
+
+ txChain.close();
+
+ cleanup(dataStore);
+ }};
+ }
+
+ @Test
+ public void testCreateChainedTransactionAfterEmptyTxReadied() throws Exception{
+ new IntegrationTestKit(getSystem()) {{
+ DistributedDataStore dataStore = setupDistributedDataStore(
+ "testCreateChainedTransactionAfterEmptyTxReadied", "test-1");
+
+ DOMStoreTransactionChain txChain = dataStore.createTransactionChain();
+
+ DOMStoreReadWriteTransaction rwTx1 = txChain.newReadWriteTransaction();
+
+ rwTx1.ready();
+
+ DOMStoreReadWriteTransaction rwTx2 = txChain.newReadWriteTransaction();
+
+ Optional<NormalizedNode<?, ?>> optional = rwTx2.read(TestModel.TEST_PATH).get(5, TimeUnit.SECONDS);
+ assertEquals("isPresent", false, optional.isPresent());
+
+ txChain.close();
+
+ cleanup(dataStore);
+ }};
+ }
+
@Test
public void testCreateChainedTransactionWhenPreviousNotReady() throws Throwable {
new IntegrationTestKit(getSystem()) {{
super(actorSystem);
}
- protected void waitForLogMessage(final Class logLevel, ActorRef subject, String logMessage){
+ protected void waitForLogMessage(final Class<?> logLevel, ActorRef subject, String logMessage){
// Wait for a specific log message to show up
final boolean result =
new JavaTestKit.EventFilter<Boolean>(logLevel
private DataNormalizer mockNormalizer() throws DataNormalizationException {
final DataNormalizer mock = mock(DataNormalizer.class);
- doReturn(new AbstractMap.SimpleEntry<YangInstanceIdentifier, NormalizedNode<?, ?>>(id, normalizedNode) {})
+ doReturn(new AbstractMap.SimpleEntry<YangInstanceIdentifier, NormalizedNode<?, ?>>(id, normalizedNode))
.when(mock).toNormalized(any(YangInstanceIdentifier.class), any(CompositeNode.class));
doReturn(compositeNode).when(mock).toLegacy(any(YangInstanceIdentifier.class), any(NormalizedNode.class));
doReturn(id).when(mock).toLegacy(any(YangInstanceIdentifier.class));
JDBCResultSet rs = new JDBCResultSet(sql);
try {
int count = 0;
- jdbcServer.execute(rs, this);
+ JDBCServer.execute(rs, this);
boolean isFirst = true;
int loc = rs.getFields().size() - 1;
int totalWidth = 0;
return cacheLoadedSuccessfuly;
}
- private static Map<Class, Set<Class>> superClassMap = new HashMap<Class, Set<Class>>();
+ private static Map<Class<?>, Set<Class<?>>> superClassMap = new HashMap<>();
- public static Set<Class> getInheritance(Class myObjectClass,
- Class returnType) {
+ public static Set<Class<?>> getInheritance(Class<?> myObjectClass,
+ Class<?> returnType) {
if (returnType != null && myObjectClass.equals(returnType)) {
- return new HashSet<Class>();
+ return new HashSet<>();
}
- Set<Class> result = superClassMap.get(myObjectClass);
+ Set<Class<?>> result = superClassMap.get(myObjectClass);
if (result != null) {
return result;
}
- result = new HashSet<Class>();
+ result = new HashSet<>();
superClassMap.put(myObjectClass, result);
if (returnType != null) {
if (!returnType.equals(myObjectClass)) {
- Class mySuperClass = myObjectClass.getSuperclass();
+ Class<?> mySuperClass = myObjectClass.getSuperclass();
while (mySuperClass != null) {
result.add(mySuperClass);
mySuperClass = mySuperClass.getSuperclass();
return result;
}
- public static Set<Class> collectInterfaces(Class cls) {
- Set<Class> result = new HashSet();
- Class myInterfaces[] = cls.getInterfaces();
+ public static Set<Class<?>> collectInterfaces(Class<?> cls) {
+ Set<Class<?>> result = new HashSet<>();
+ Class<?> myInterfaces[] = cls.getInterfaces();
if (myInterfaces != null) {
- for (Class in : myInterfaces) {
+ for (Class<?> in : myInterfaces) {
result.add(in);
result.addAll(collectInterfaces(in));
}
map.put(blNode.getBluePrintNodeName(), blNode);
}
- public Class getGenericType(ParameterizedType type) {
+ public Class<?> getGenericType(ParameterizedType type) {
Type[] typeArguments = type.getActualTypeArguments();
for (Type typeArgument : typeArguments) {
if (typeArgument instanceof ParameterizedType) {
ParameterizedType pType = (ParameterizedType) typeArgument;
- return (Class) pType.getRawType();
+ return (Class<?>) pType.getRawType();
} else if (typeArgument instanceof Class) {
- return (Class) typeArgument;
+ return (Class<?>) typeArgument;
}
}
return null;
}
- public Class getMethodReturnTypeFromGeneric(Method m) {
+ public Class<?> getMethodReturnTypeFromGeneric(Method m) {
Type rType = m.getGenericReturnType();
if (rType instanceof ParameterizedType) {
return getGenericType((ParameterizedType) rType);
this.children.add(ch);
}
- public boolean isModelChild(Class p) {
+ public boolean isModelChild(Class<?> p) {
if (this.relations.size() == 0) {
return false;
}
return "Unknown";
}
- public Class getInterface() {
+ public Class<?> getInterface() {
return this.myInterface;
}
}
}
- public List execute(Object o) {
- List result = new LinkedList();
+ public List<?> execute(Object o) {
+ List<Object> result = new LinkedList<>();
if (o == null) {
return null;
}
if (Set.class.isAssignableFrom(o.getClass())) {
- Set lst = (Set) o;
+ Set<?> lst = (Set<?>) o;
for (Object oo : lst) {
addToResult(result, execute(oo));
}
return result;
} else if (List.class.isAssignableFrom(o.getClass())) {
- List lst = (List) o;
+ List<?> lst = (List<?>) o;
for (Object oo : lst) {
addToResult(result, execute(oo));
}
return result;
}
- public static void addToResult(List result, Object o) {
+ private static void addToResult(List<Object> result, Object o) {
if (o == null) {
return;
}
if (Set.class.isAssignableFrom(o.getClass())) {
- Set lst = (Set) o;
+ Set<?> lst = (Set<?>) o;
for (Object oo : lst) {
result.add(oo);
}
} else if (List.class.isAssignableFrom(o.getClass())) {
- List lst = (List) o;
+ List<?> lst = (List<?>) o;
for (Object oo : lst) {
result.add(oo);
}
private String name = null;
private String tableName = null;
private int charWidth = -1;
- private Class type = null;
+ private Class<?> type = null;
private transient Object bluePrintNode = null;
private String origName = null;
private String origTableName = null;
types.put(Status.class, Status.class);
}
- public static boolean isColumnType(Class cls) {
+ public static boolean isColumnType(Class<?> cls) {
return types.containsKey(cls);
}
return "NULL";
}
- public static Class getTypeForODLColumn(Object odlNode){
+ public static Class<?> getTypeForODLColumn(Object odlNode){
Object type = get(odlNode,"type");
if(type instanceof Uint32 || type instanceof Uint64){
return long.class;
return 1;
}
- public int isObjectFitCriteria(Object element, Class cls) {
+ public int isObjectFitCriteria(Object element, Class<?> cls) {
Map<XSQLColumn, List<XSQLCriteria>> tblCriteria = criteria.get(cls
.getName());
if (tblCriteria == null) {
Messages.BucketStoreMessages.UpdateRemoteBuckets.class);
}
- private JavaTestKit createProbeForMessage(ActorSystem node, ActorPath subjectPath, final Class clazz) {
+ private JavaTestKit createProbeForMessage(ActorSystem node, ActorPath subjectPath, final Class<?> clazz) {
final JavaTestKit probe = new JavaTestKit(node);
ConditionalProbe conditionalProbe =
notifications.add(new QName(notificationType.toString()));
String notificationStreamName = RemoteStreamTools.createNotificationStream(salRemoteService, notifications);
final Map<String,EventStreamInfo> desiredEventStream = RemoteStreamTools.createEventStream(restconfClientContext, notificationStreamName);
- RemoteNotificationListener remoteNotificationListener = new RemoteNotificationListener(listener);
+ RemoteNotificationListener<T> remoteNotificationListener = new RemoteNotificationListener<T>(listener);
final ListenerRegistration<?> listenerRegistration = restconfClientContext.getEventStreamContext(desiredEventStream.get(desiredEventStream.get(notificationStreamName)))
.registerNotificationListener(remoteNotificationListener);
package org.opendaylight.controller.sal.restconf.broker.listeners;
import org.opendaylight.controller.sal.binding.api.NotificationListener;
+import org.opendaylight.yangtools.yang.binding.Notification;
-public class RemoteNotificationListener implements org.opendaylight.yangtools.yang.binding.NotificationListener {
+public class RemoteNotificationListener<T extends Notification> implements org.opendaylight.yangtools.yang.binding.NotificationListener {
- org.opendaylight.controller.sal.binding.api.NotificationListener listener;
+ NotificationListener<T> listener;
- public RemoteNotificationListener(NotificationListener listener){
+ public RemoteNotificationListener(NotificationListener<T> listener){
this.listener = listener;
}
- public NotificationListener getListener(){
+ public NotificationListener<T> getListener() {
return this.listener;
}
import org.opendaylight.yangtools.yang.binding.Notification;
-public class SalNotificationListener implements NotificationListener {
- private NotificationListener notificationListener;
+public class SalNotificationListener<T extends Notification> implements NotificationListener<T> {
+ private NotificationListener<T> notificationListener;
- public SalNotificationListener( NotificationListener notificationListener){
+ public SalNotificationListener( NotificationListener<T> notificationListener){
this.notificationListener = notificationListener;
}
@Override
public void onNotification(Notification notification) {
- this.notificationListener.onNotification(notification);
+ this.notificationListener.onNotification((T)notification);
}
}
Util.checkType(listOfStrings, List.class);
StringBuilder b = new StringBuilder();
- for (Object character: (List)listOfStrings) {
+ for (Object character: (List<?>)listOfStrings) {
Util.checkType(character, String.class);
b.append(character);
}
package org.opendaylight.controller.netconf.confignetconfconnector.operations.runtimerpc;
import static org.junit.Assert.assertEquals;
-
+import com.google.common.collect.ImmutableMap;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
return Arrays.asList(new Object[][] {
// With namespaces
{ "/a:modules/a:module[a:name='instanceName'][a:type='moduleType']/b:listener-state[b:peer-id='127.0.0.1']",
- new HashMap<String, String>() {{
- put("listener-state", "127.0.0.1");
- }}},
+ new HashMap<>(ImmutableMap.of("listener-state", "127.0.0.1"))},
{ "/a:modules/a:module[a:name='instanceName'][a:type='moduleType']",
null},
{ "/modules/module[name=instanceName and type=moduleType]/inner[key=\"b\"]", Collections.singletonMap("inner", "b")},
{ "/modules/module[name=instanceName and type=\"moduleType\"]/inner[key2=a]/inner2[key=b]",
- new HashMap<String, String>() {{
- put("inner", "a");
- put("inner2", "b");
- }}
+ new HashMap<>(ImmutableMap.of("inner", "a", "inner2", "b"))
},
});
}
NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, null);
negotiator.channelActive(null);
- Set caps = Sets.newSet("a", "b");
+ Set<String> caps = Sets.newSet("a", "b");
NetconfHelloMessage helloServerMessage = NetconfHelloMessage.createServerHello(caps, 10);
negotiator.handleMessage(helloServerMessage);
verify(promise).setSuccess(anyObject());
NetconfClientSessionNegotiator negotiator = createNetconfClientSessionNegotiator(promise, exiMessage);
negotiator.channelActive(null);
- Set caps = Sets.newSet("exi:1.0");
+ Set<String> caps = Sets.newSet("exi:1.0");
NetconfHelloMessage helloMessage = NetconfHelloMessage.createServerHello(caps, 10);
doAnswer(new Answer<Object>() {
private Channel channel;
private ChannelFuture channelFuture;
- Set caps;
+ Set<String> caps;
private NetconfHelloMessage helloMessage;
private NetconfMessage message;
private NetconfClientSessionListener sessionListener;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import io.netty.channel.Channel;
-import java.util.List;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
public void testSessions() throws Exception {
doReturn("sessToStr").when(managementSession).toString();
service.onSessionUp(managementSession);
- List list = Lists.newArrayList(managementSession);
}
@Test(expected = RuntimeException.class)
public void testGetSchemas3() throws Exception {
doReturn("").when(managementSession).toString();
Capability cap = mock(Capability.class);
- Set caps = Sets.newHashSet(cap);
- Set services = Sets.newHashSet(operationService);
+ Set<Capability> caps = Sets.newHashSet(cap);
+ Set<NetconfOperationService> services = Sets.newHashSet(operationService);
doReturn(snapshot).when(operationProvider).openSnapshot(anyString());
doReturn(services).when(snapshot).getServices();
doReturn(caps).when(operationService).getCapabilities();
- Optional opt = mock(Optional.class);
+ Optional<String> opt = mock(Optional.class);
doReturn(opt).when(cap).getCapabilitySchema();
doReturn(true).when(opt).isPresent();
doReturn(opt).when(cap).getModuleNamespace();
doReturn("namespace").when(opt).get();
- Optional optRev = Optional.of("rev");
+ Optional<String> optRev = Optional.of("rev");
doReturn(optRev).when(cap).getRevision();
doReturn(Optional.of("modName")).when(cap).getModuleName();
doReturn(Optional.of(Lists.newArrayList("loc"))).when(cap).getLocation();
if (classes == null || classes.size() == 0) return;
Map<String,String> names = new HashMap<String,String>();
StringBuilder conflictsMsg = new StringBuilder();
- for (Class c : classes) {
- XmlRootElement root = (XmlRootElement) c.getAnnotation(XmlRootElement.class);
+ for (Class<?> c : classes) {
+ XmlRootElement root = c.getAnnotation(XmlRootElement.class);
if (root == null) continue;
String rootName = root.name();
if ("##default".equals(rootName)) {
}
@Override
- public Enumeration findEntries(String path, String filePattern, boolean recurse) {
+ public Enumeration<URL> findEntries(String path, String filePattern, boolean recurse) {
return Collections.enumeration(classes);
}
@QueryParam("name") String queryFirewallPolicyName,
@QueryParam("description") String querySecurityPolicyDescription,
@QueryParam("shared") String querySecurityPolicyIsShared,
- @QueryParam("firewall_rules") List querySecurityPolicyFirewallRules,
+ @QueryParam("firewall_rules") List<String> querySecurityPolicyFirewallRules,
@QueryParam("audited") Boolean querySecurityPolicyIsAudited,
// pagination
@QueryParam("limit") String limit,