dheldh77 / project_share_blog

2 stars 0 forks source link

Use single cassandra test container for all tests #18

Open jyaquinas opened 2 years ago

jyaquinas commented 2 years ago

Ref: https://www.testcontainers.org/test_framework_integration/manual_lifecycle_control/#singleton-containers https://rieckpil.de/reuse-containers-with-testcontainers-for-fast-integration-tests/

@SpringBootTest
public abstract class CassandraBaseContainer {

    static final CassandraContainer cassandraContainer;
    static {
        cassandraContainer =
                (CassandraContainer) new CassandraContainer("cassandra:4.0.3")
                        .withExposedPorts(9042)
                        .withReuse(true);

        cassandraContainer.start();
        setupCassandra();
    }

    private static final String KEYSPACE_NAME = "TestKeyspace";

    static void setupCassandra() {
        System.setProperty("spring.data.cassandra.keyspace-name", KEYSPACE_NAME);
        System.setProperty("spring.data.cassandra.contact-points", cassandraContainer.getHost());
        System.setProperty("spring.data.cassandra.port",
                String.valueOf(cassandraContainer.getMappedPort(9042)));

        try (Session session = cassandraContainer.getCluster().connect()) {
            session.execute("CREATE KEYSPACE IF NOT EXISTS " + KEYSPACE_NAME +
                    " WITH replication = \n" +
                    "{'class':'SimpleStrategy','replication_factor':'1'};");
        }
    }

}

Screen Shot 2022-05-19 at 11 05 45 PM

Screen Shot 2022-05-19 at 11 06 03 PM

아직 디버깅중..

dheldh77 commented 2 years ago

와 이거 그때말한 도커 문제가 아니고 다른 문제이면 어떡하지..?

jyaquinas commented 2 years ago
Screen Shot 2022-05-21 at 3 36 04 PM

Test passes when executed within the class ('Run PostsRepositoryTest'), but fails when executed from the package ('Run tests in com.example...')

jyaquinas commented 2 years ago
Screen Shot 2022-05-21 at 3 42 49 PM