import java.util.concurrent.ExecutionException;
import javax.annotation.concurrent.ThreadSafe;
import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.common.api.data.AsyncTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
@Override
public long getRoutesCount(final TablesKey key) {
- try {
- final Optional<Tables> tableMaybe = this.dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL,
+ try (final ReadOnlyTransaction tx = this.dataBroker.newReadOnlyTransaction()) {
+ final Optional<Tables> tableMaybe = tx.read(LogicalDatastoreType.OPERATIONAL,
getInstanceIdentifier().child(LocRib.class).child(Tables.class, key)).checkedGet();
if (tableMaybe.isPresent()) {
final Tables table = tableMaybe.get();
}
}
} catch (final ReadFailedException e) {
- //no-op
+ LOG.debug("Failed to read tables", e);
}
return 0;
}
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.any;
-
import com.google.common.base.Optional;
import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
this.peer = new ApplicationPeer(new ApplicationRibId("t"), new Ipv4Address("127.0.0.1"), this.r);
this.r.onGlobalContextUpdated(schemaContext);
final ReadOnlyTransaction readTx = Mockito.mock(ReadOnlyTransaction.class);
+ Mockito.doNothing().when(readTx).close();
Mockito.doReturn(readTx).when(this.dps).newReadOnlyTransaction();
final CheckedFuture<Optional<DataObject>, ReadFailedException> readFuture = Mockito.mock(CheckedFuture.class);
Mockito.doReturn(Optional.<DataObject>absent()).when(readFuture).checkedGet();