void testTableWithUUIDPicked()

in src/testFixtures/java/org/apache/cassandra/sidecar/snapshots/AbstractSnapshotPathBuilderTest.java [514:599]


    void testTableWithUUIDPicked(@TempDir File tempDir) throws IOException
    {
        File dataDir = new File(tempDir, "data");
        dataDir.mkdirs();

        InstancesConfig mockInstancesConfig = mock(InstancesConfig.class);
        InstanceMetadata mockInstanceMeta = mock(InstanceMetadata.class);

        when(mockInstancesConfig.instanceFromHost("localhost")).thenReturn(mockInstanceMeta);
        when(mockInstanceMeta.dataDirs()).thenReturn(Collections.singletonList(dataDir.getAbsolutePath()));

        File atable = new File(dataDir, "data/ks1/a_table");
        atable.mkdirs();
        File atableSnapshot = new File(atable, "snapshots/a_snapshot");
        atableSnapshot.mkdirs();
        new File(atable, "snapshots/a_snapshot/data.db").createNewFile();
        new File(atable, "snapshots/a_snapshot/index.db").createNewFile();
        new File(atable, "snapshots/a_snapshot/nb-203-big-TOC.txt").createNewFile();

        File atableWithUUID = new File(dataDir, "data/ks1/a_table-a72c8740a57611ec935db766a70c44a1");
        atableWithUUID.mkdirs();
        File atableWithUUIDSnapshot = new File(atableWithUUID, "snapshots/a_snapshot");
        atableWithUUIDSnapshot.mkdirs();

        new File(atableWithUUID, "snapshots/a_snapshot/data.db").createNewFile();
        new File(atableWithUUID, "snapshots/a_snapshot/index.db").createNewFile();
        new File(atableWithUUID, "snapshots/a_snapshot/nb-203-big-TOC.txt").createNewFile();
        atableWithUUID.setLastModified(System.currentTimeMillis() + 2000000);

        String expectedPath;
        // a_table and a_table-<TABLE_UUID> - the latter should be picked
        SnapshotPathBuilder newBuilder = new SnapshotPathBuilder(vertx, mockInstancesConfig, validator, executorPools);
        expectedPath = atableWithUUID.getAbsolutePath() + "/snapshots/a_snapshot/data.db";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new StreamSSTableComponentRequest("ks1",
                                                                        "a_table",
                                                                        "a_snapshot",
                                                                        "data.db")),
                               expectedPath);

        expectedPath = atableWithUUID.getAbsolutePath() + "/snapshots/a_snapshot";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new SnapshotRequest("ks1",
                                                          "a_table",
                                                          "a_snapshot",
                                                          false)),
                               expectedPath);

        expectedPath = atableWithUUID.getAbsolutePath() + "/snapshots/a_snapshot/index.db";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new StreamSSTableComponentRequest("ks1",
                                                                        "a_table",
                                                                        "a_snapshot",
                                                                        "index.db")),
                               expectedPath);

        expectedPath = atableWithUUID.getAbsolutePath() + "/snapshots/a_snapshot";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new SnapshotRequest("ks1",
                                                          "a_table",
                                                          "a_snapshot",
                                                          false)),
                               expectedPath);

        expectedPath = atableWithUUID.getAbsolutePath() + "/snapshots/a_snapshot/nb-203-big-TOC.txt";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new StreamSSTableComponentRequest("ks1",
                                                                        "a_table",
                                                                        "a_snapshot",
                                                                        "nb-203-big-TOC.txt")),
                               expectedPath);

        expectedPath = atableWithUUID.getAbsolutePath() + "/snapshots/a_snapshot";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new SnapshotRequest("ks1",
                                                          "a_table",
                                                          "a_snapshot",
                                                          false)),
                               expectedPath);
    }