Search in sources :

Example 1 with BackupDatastoreInputBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.BackupDatastoreInputBuilder in project controller by opendaylight.

the class ClusterAdminRpcServiceTest method testBackupDatastore.

@Test
public void testBackupDatastore() throws Exception {
    MemberNode node = MemberNode.builder(memberNodes).akkaConfig("Member1").moduleShardsConfig("module-shards-member1.conf").waitForShardLeader("cars", "people").testName("testBackupDatastore").build();
    String fileName = "target/testBackupDatastore";
    new File(fileName).delete();
    ClusterAdminRpcService service = new ClusterAdminRpcService(node.configDataStore(), node.operDataStore(), null);
    RpcResult<Void> rpcResult = service.backupDatastore(new BackupDatastoreInputBuilder().setFilePath(fileName).build()).get(5, TimeUnit.SECONDS);
    verifySuccessfulRpcResult(rpcResult);
    try (FileInputStream fis = new FileInputStream(fileName)) {
        List<DatastoreSnapshot> snapshots = SerializationUtils.deserialize(fis);
        assertEquals("DatastoreSnapshot size", 2, snapshots.size());
        ImmutableMap<String, DatastoreSnapshot> map = ImmutableMap.of(snapshots.get(0).getType(), snapshots.get(0), snapshots.get(1).getType(), snapshots.get(1));
        verifyDatastoreSnapshot(node.configDataStore().getActorContext().getDataStoreName(), map.get(node.configDataStore().getActorContext().getDataStoreName()), "cars", "people");
    } finally {
        new File(fileName).delete();
    }
    // Test failure by killing a shard.
    node.configDataStore().getActorContext().getShardManager().tell(node.datastoreContextBuilder().shardInitializationTimeout(200, TimeUnit.MILLISECONDS).build(), ActorRef.noSender());
    ActorRef carsShardActor = node.configDataStore().getActorContext().findLocalShard("cars").get();
    node.kit().watch(carsShardActor);
    carsShardActor.tell(PoisonPill.getInstance(), ActorRef.noSender());
    node.kit().expectTerminated(carsShardActor);
    rpcResult = service.backupDatastore(new BackupDatastoreInputBuilder().setFilePath(fileName).build()).get(5, TimeUnit.SECONDS);
    assertFalse("isSuccessful", rpcResult.isSuccessful());
    assertEquals("getErrors", 1, rpcResult.getErrors().size());
}
Also used : MemberNode(org.opendaylight.controller.cluster.datastore.MemberNode) ActorRef(akka.actor.ActorRef) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DatastoreSnapshot(org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot) File(java.io.File) BackupDatastoreInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.BackupDatastoreInputBuilder) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

ActorRef (akka.actor.ActorRef)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Test (org.junit.Test)1 MemberNode (org.opendaylight.controller.cluster.datastore.MemberNode)1 DatastoreSnapshot (org.opendaylight.controller.cluster.datastore.persisted.DatastoreSnapshot)1 BackupDatastoreInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.cluster.admin.rev151013.BackupDatastoreInputBuilder)1