import akka.actor.Status.Failure;
import akka.actor.Terminated;
import akka.dispatch.Dispatchers;
-import akka.testkit.JavaTestKit;
import akka.testkit.TestActorRef;
+import akka.testkit.javadsl.TestKit;
import com.google.common.base.Throwables;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
}
@Test
- public void testOnReceiveReadData() throws Exception {
- new JavaTestKit(getSystem()) {
+ public void testOnReceiveReadData() {
+ new TestKit(getSystem()) {
{
testOnReceiveReadData(newTransactionActor(RO, readOnlyTransaction(), "testReadDataRO"));
}
@Test
- public void testOnReceiveReadDataWhenDataNotFound() throws Exception {
- new JavaTestKit(getSystem()) {
+ public void testOnReceiveReadDataWhenDataNotFound() {
+ new TestKit(getSystem()) {
{
testOnReceiveReadDataWhenDataNotFound(
newTransactionActor(RO, readOnlyTransaction(), "testReadDataWhenDataNotFoundRO"));
}
@Test
- public void testOnReceiveDataExistsPositive() throws Exception {
- new JavaTestKit(getSystem()) {
+ public void testOnReceiveDataExistsPositive() {
+ new TestKit(getSystem()) {
{
testOnReceiveDataExistsPositive(
newTransactionActor(RO, readOnlyTransaction(), "testDataExistsPositiveRO"));
}
@Test
- public void testOnReceiveDataExistsNegative() throws Exception {
- new JavaTestKit(getSystem()) {
+ public void testOnReceiveDataExistsNegative() {
+ new TestKit(getSystem()) {
{
testOnReceiveDataExistsNegative(
newTransactionActor(RO, readOnlyTransaction(), "testDataExistsNegativeRO"));
}
@Test
- public void testOnReceiveBatchedModifications() throws Exception {
- new JavaTestKit(getSystem()) {
+ public void testOnReceiveBatchedModifications() {
+ new TestKit(getSystem()) {
{
ShardDataTreeTransactionParent parent = Mockito.mock(ShardDataTreeTransactionParent.class);
DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
}
@Test
- public void testOnReceiveBatchedModificationsReadyWithoutImmediateCommit() throws Exception {
- new JavaTestKit(getSystem()) {
+ public void testOnReceiveBatchedModificationsReadyWithoutImmediateCommit() {
+ new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(),
"testOnReceiveBatchedModificationsReadyWithoutImmediateCommit");
- JavaTestKit watcher = new JavaTestKit(getSystem());
+ TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
YangInstanceIdentifier writePath = TestModel.TEST_PATH;
assertEquals("getNumBatched", 1, reply.getNumBatched());
batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
- batched.setReady(true);
+ batched.setReady();
batched.setTotalMessagesSent(2);
transaction.tell(batched, getRef());
}
@Test
- public void testOnReceiveBatchedModificationsReadyWithImmediateCommit() throws Exception {
- new JavaTestKit(getSystem()) {
+ public void testOnReceiveBatchedModificationsReadyWithImmediateCommit() {
+ new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(),
"testOnReceiveBatchedModificationsReadyWithImmediateCommit");
- JavaTestKit watcher = new JavaTestKit(getSystem());
+ TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
YangInstanceIdentifier writePath = TestModel.TEST_PATH;
BatchedModifications batched = new BatchedModifications(nextTransactionId(),
DataStoreVersions.CURRENT_VERSION);
batched.addModification(new WriteModification(writePath, writeData));
- batched.setReady(true);
+ batched.setReady();
batched.setDoCommitOnReady(true);
batched.setTotalMessagesSent(1);
@Test(expected = TestException.class)
public void testOnReceiveBatchedModificationsFailure() throws Exception {
- new JavaTestKit(getSystem()) {
+ new TestKit(getSystem()) {
{
ShardDataTreeTransactionParent parent = Mockito.mock(ShardDataTreeTransactionParent.class);
final ActorRef transaction = newTransactionActor(RW, mockWriteTx,
"testOnReceiveBatchedModificationsFailure");
- JavaTestKit watcher = new JavaTestKit(getSystem());
+ TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
YangInstanceIdentifier path = TestModel.TEST_PATH;
expectMsgClass(duration("5 seconds"), akka.actor.Status.Failure.class);
batched = new BatchedModifications(tx1, DataStoreVersions.CURRENT_VERSION);
- batched.setReady(true);
+ batched.setReady();
batched.setTotalMessagesSent(2);
transaction.tell(batched, getRef());
watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
if (failure != null) {
- Throwables.propagateIfInstanceOf(failure.cause(), Exception.class);
- Throwables.propagate(failure.cause());
+ Throwables.propagateIfPossible(failure.cause(), Exception.class);
+ throw new RuntimeException(failure.cause());
}
}
};
@Test(expected = IllegalStateException.class)
public void testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount() throws Exception {
- new JavaTestKit(getSystem()) {
+ new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(),
"testOnReceiveBatchedModificationsReadyWithIncorrectTotalMessageCount");
- JavaTestKit watcher = new JavaTestKit(getSystem());
+ TestKit watcher = new TestKit(getSystem());
watcher.watch(transaction);
BatchedModifications batched = new BatchedModifications(nextTransactionId(),
DataStoreVersions.CURRENT_VERSION);
- batched.setReady(true);
+ batched.setReady();
batched.setTotalMessagesSent(2);
transaction.tell(batched, getRef());
watcher.expectMsgClass(duration("5 seconds"), Terminated.class);
if (failure != null) {
- Throwables.propagateIfInstanceOf(failure.cause(), Exception.class);
- Throwables.propagate(failure.cause());
+ Throwables.throwIfInstanceOf(failure.cause(), Exception.class);
+ Throwables.throwIfUnchecked(failure.cause());
+ throw new RuntimeException(failure.cause());
}
}
};
}
@Test
- public void testReadWriteTxOnReceiveCloseTransaction() throws Exception {
- new JavaTestKit(getSystem()) {
+ public void testReadWriteTxOnReceiveCloseTransaction() {
+ new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(RW, readWriteTransaction(),
"testReadWriteTxOnReceiveCloseTransaction");
}
@Test
- public void testWriteOnlyTxOnReceiveCloseTransaction() throws Exception {
- new JavaTestKit(getSystem()) {
+ public void testWriteOnlyTxOnReceiveCloseTransaction() {
+ new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(WO, readWriteTransaction(),
"testWriteTxOnReceiveCloseTransaction");
}
@Test
- public void testReadOnlyTxOnReceiveCloseTransaction() throws Exception {
- new JavaTestKit(getSystem()) {
+ public void testReadOnlyTxOnReceiveCloseTransaction() {
+ new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(TransactionType.READ_ONLY, readOnlyTransaction(),
"testReadOnlyTxOnReceiveCloseTransaction");
datastoreContext = DatastoreContext.newBuilder().shardTransactionIdleTimeout(
500, TimeUnit.MILLISECONDS).build();
- new JavaTestKit(getSystem()) {
+ new TestKit(getSystem()) {
{
final ActorRef transaction = newTransactionActor(RW, readWriteTransaction(),
"testShardTransactionInactivity");