Search in sources :

Example 1 with AeshTestConnection

use of org.infinispan.server.test.core.AeshTestConnection in project infinispan by infinispan.

the class CliBackupManagerIT method testBackupToCustomDir.

@Test
public void testBackupToCustomDir() {
    startSourceCluster();
    String backupName = "server-backup";
    String fileName = backupName + ".zip";
    File localBackupDir = new File(WORKING_DIR, "custom-dir");
    localBackupDir.mkdir();
    localBackupDir.setWritable(true, false);
    File serverBackupDir = new File(source.driver.syncFilesToServer(0, localBackupDir.getAbsolutePath()));
    source.driver.syncFilesToServer(1, localBackupDir.getAbsolutePath());
    try (AeshTestConnection t = cli(source)) {
        t.clear();
        t.send(String.format("backup create -d %s -n %s", serverBackupDir.getPath(), backupName));
        // Ensure that the backup has finished before stopping the source cluster
        t.send("backup get --no-content " + backupName);
    }
    localBackupDir = new File(source.driver.syncFilesFromServer(0, serverBackupDir.getAbsolutePath()));
    if (!localBackupDir.getName().equals("custom-dir")) {
        localBackupDir = new File(localBackupDir, "custom-dir");
    }
    assertTrue(new File(localBackupDir, backupName + "/" + fileName).exists());
}
Also used : AeshTestConnection(org.infinispan.server.test.core.AeshTestConnection) File(java.io.File) ZipFile(java.util.zip.ZipFile) Test(org.junit.Test)

Example 2 with AeshTestConnection

use of org.infinispan.server.test.core.AeshTestConnection in project infinispan by infinispan.

the class CliBackupManagerIT method testBackupUpload.

@Test
public void testBackupUpload() throws Exception {
    startSourceCluster();
    Path createdBackup;
    try (AeshTestConnection t = cli(source)) {
        t.send("create cache --template=org.infinispan.DIST_SYNC backupCache");
        t.send("cd caches/backupCache");
        t.send("put k1 v1");
        t.send("ls");
        t.assertContains("k1");
        t.clear();
        String backupName = "example-backup";
        t.send("backup create -n " + backupName);
        t.send("backup get " + backupName);
        Thread.sleep(1000);
        t.send("backup delete " + backupName);
        String fileName = backupName + ".zip";
        createdBackup = Paths.get(System.getProperty("user.dir")).resolve(fileName);
    }
    stopSourceCluster();
    startTargetCluster();
    try (AeshTestConnection t = cli(target)) {
        t.send("backup restore -u " + createdBackup);
        Thread.sleep(1000);
        t.send("ls caches/backupCache");
        t.assertContains("k1");
    }
    Files.delete(createdBackup);
}
Also used : Path(java.nio.file.Path) AeshTestConnection(org.infinispan.server.test.core.AeshTestConnection) Test(org.junit.Test)

Example 3 with AeshTestConnection

use of org.infinispan.server.test.core.AeshTestConnection in project infinispan by infinispan.

the class CliBackupManagerIT method testBackupFromServerDir.

@Test
public void testBackupFromServerDir() throws Exception {
    startSourceCluster();
    String backupName = "server-backup";
    String fileName = backupName + ".zip";
    try (AeshTestConnection t = cli(source)) {
        t.send("create cache --template=org.infinispan.DIST_SYNC backupCache");
        t.send("cd caches/backupCache");
        t.send("put k1 v1");
        t.send("ls");
        t.assertContains("k1");
        t.clear();
        t.send("backup create -n " + backupName);
        // Ensure that the backup has finished before stopping the source cluster
        t.send("backup get --no-content " + backupName);
    }
    source.driver.syncFilesFromServer(0, "data");
    stopSourceCluster();
    startTargetCluster();
    Path createdBackup = source.driver.getRootDir().toPath().resolve("0/data/backups").resolve(backupName).resolve(fileName);
    createdBackup = Paths.get(target.driver.syncFilesToServer(0, createdBackup.toString()));
    try (AeshTestConnection t = cli(target)) {
        t.send("backup restore " + createdBackup);
        Thread.sleep(1000);
        t.send("ls caches/backupCache");
        t.assertContains("k1");
    }
    Files.deleteIfExists(createdBackup);
}
Also used : Path(java.nio.file.Path) AeshTestConnection(org.infinispan.server.test.core.AeshTestConnection) Test(org.junit.Test)

Example 4 with AeshTestConnection

use of org.infinispan.server.test.core.AeshTestConnection in project infinispan by infinispan.

the class CliBackupManagerIT method testPartialBackup.

@Test
public void testPartialBackup() throws Exception {
    startSourceCluster();
    String backupName = "partial-backup";
    String fileName = backupName + ".zip";
    try (AeshTestConnection t = cli(source)) {
        t.send("backup create --templates=* -n " + backupName);
        // Ensure that the backup has finished before stopping the source cluster
        t.send("backup get --no-content " + backupName);
    }
    source.driver.syncFilesFromServer(0, "data");
    Path createdBackup = source.driver.getRootDir().toPath().resolve("0/data/backups").resolve(backupName).resolve(fileName);
    try (ZipFile zip = new ZipFile(createdBackup.toFile())) {
        // Ensure that only cache-configs are present
        assertNotNull(zipResourceDir(TEMPLATES));
        assertResourceDoesntExist(zip, CACHES, COUNTERS, PROTO_SCHEMAS, TASKS);
    }
    Files.delete(createdBackup);
}
Also used : Path(java.nio.file.Path) ZipFile(java.util.zip.ZipFile) AeshTestConnection(org.infinispan.server.test.core.AeshTestConnection) Test(org.junit.Test)

Example 5 with AeshTestConnection

use of org.infinispan.server.test.core.AeshTestConnection in project infinispan by infinispan.

the class CliBackupManagerIT method cli.

private AeshTestConnection cli(Cluster cluster) {
    AeshTestConnection t = new AeshTestConnection();
    CLI.main(new AeshDelegatingShell(t), new String[] {}, new Properties());
    String host = cluster.driver.getServerAddress(0).getHostAddress();
    int port = cluster.driver.getServerSocket(0, 11222).getPort();
    t.send(String.format("connect %s:%d", host, port));
    t.assertContains("//containers/default]>");
    t.clear();
    return t;
}
Also used : AeshDelegatingShell(org.infinispan.cli.impl.AeshDelegatingShell) AeshTestConnection(org.infinispan.server.test.core.AeshTestConnection) Properties(java.util.Properties)

Aggregations

AeshTestConnection (org.infinispan.server.test.core.AeshTestConnection)23 AeshDelegatingShell (org.infinispan.cli.impl.AeshDelegatingShell)19 Test (org.junit.Test)14 File (java.io.File)3 Path (java.nio.file.Path)3 Properties (java.util.Properties)3 ZipFile (java.util.zip.ZipFile)2 IOException (java.io.IOException)1 List (java.util.List)1 Consumer (java.util.function.Consumer)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 Config (org.aesh.terminal.utils.Config)1 CLI (org.infinispan.cli.commands.CLI)1 CommonsTestingUtil (org.infinispan.commons.test.CommonsTestingUtil)1 Util (org.infinispan.commons.util.Util)1 BackupConfiguration (org.infinispan.configuration.cache.BackupConfiguration)1 CacheMode (org.infinispan.configuration.cache.CacheMode)1