void testLastModifiedTablePicked()

in src/testFixtures/java/org/apache/cassandra/sidecar/snapshots/AbstractSnapshotPathBuilderTest.java [603:698]


    void testLastModifiedTablePicked(@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 table4Old = new File(dataDir, "data/ks4/table4-a6442310a57611ec8b980b0b2009844e1");
        table4Old.mkdirs();

        // table was dropped and recreated. The table gets a new uuid
        File table4OldSnapshot = new File(table4Old, "snapshots/this_is_a_valid_snapshot_name_i_❤_u");
        table4OldSnapshot.mkdirs();
        // create some files inside snapshot this_is_a_valid_snapshot_name_i_❤_u in dataDir1
        new File(table4Old, "snapshots/this_is_a_valid_snapshot_name_i_❤_u/data.db").createNewFile();
        new File(table4Old, "snapshots/this_is_a_valid_snapshot_name_i_❤_u/index.db").createNewFile();
        new File(table4Old, "snapshots/this_is_a_valid_snapshot_name_i_❤_u/nb-203-big-TOC.txt").createNewFile();

        File table4New = new File(dataDir, "data/ks4/table4-a72c8740a57611ec935db766a70c44a1");
        table4New.mkdirs();

        File table4NewSnapshot = new File(table4New, "snapshots/this_is_a_valid_snapshot_name_i_❤_u");
        table4NewSnapshot.mkdirs();

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

        String expectedPath;
        SnapshotPathBuilder newBuilder = new SnapshotPathBuilder(vertx, mockInstancesConfig, validator, executorPools);
        // table4-a72c8740a57611ec935db766a70c44a1 is the last modified, so it is the correct directory
        expectedPath = table4New.getAbsolutePath()
                       + "/snapshots/this_is_a_valid_snapshot_name_i_❤_u/data.db";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new StreamSSTableComponentRequest("ks4",
                                                                        "table4",
                                                                        "this_is_a_valid_snapshot_name_i_❤_u",
                                                                        "data.db")),
                               expectedPath);

        expectedPath = table4New.getAbsolutePath()
                       + "/snapshots/this_is_a_valid_snapshot_name_i_❤_u";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new SnapshotRequest("ks4",
                                                          "table4",
                                                          "this_is_a_valid_snapshot_name_i_❤_u",
                                                          false)),
                               expectedPath);

        expectedPath = table4New.getAbsolutePath()
                       + "/snapshots/this_is_a_valid_snapshot_name_i_❤_u/index.db";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new StreamSSTableComponentRequest("ks4",
                                                                        "table4",
                                                                        "this_is_a_valid_snapshot_name_i_❤_u",
                                                                        "index.db")),
                               expectedPath);

        expectedPath = table4New.getAbsolutePath()
                       + "/snapshots/this_is_a_valid_snapshot_name_i_❤_u";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new SnapshotRequest("ks4",
                                                          "table4",
                                                          "this_is_a_valid_snapshot_name_i_❤_u",
                                                          false)),
                               expectedPath);

        expectedPath = table4New.getAbsolutePath()
                       + "/snapshots/this_is_a_valid_snapshot_name_i_❤_u/nb-203-big-TOC.txt";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new StreamSSTableComponentRequest("ks4",
                                                                        "table4",
                                                                        "this_is_a_valid_snapshot_name_i_❤_u",
                                                                        "nb-203-big-TOC.txt")),
                               expectedPath);

        expectedPath = table4New.getAbsolutePath()
                       + "/snapshots/this_is_a_valid_snapshot_name_i_❤_u";
        succeedsWhenPathExists(newBuilder
                               .build("localhost",
                                      new SnapshotRequest("ks4",
                                                          "table4",
                                                          "this_is_a_valid_snapshot_name_i_❤_u",
                                                          false)),
                               expectedPath);
    }