embedded-cassandra

embedded-cassandra not working in java 21


I recently upgraded my build to java 21 from 11. I updated my pom to the latst version of embedded-cassandra. When I run my in-memory tests, I get the following error:

2024-03-20 19:01:59.428(GMT) ERROR Unrecognized VM option 'UseBiasedLocking'
2024-03-20 19:01:59.431(GMT) ERROR Error: Could not create the Java Virtual Machine.
2024-03-20 19:01:59.431(GMT) ERROR Error: A fatal exception has occurred. Program will exit.

Is there a solution for this problem? Does embedded-cassandra support java 21?


Solution

  • It is not about Embedded Cassandra itself. As far as I know, Apache Cassandra does not support jdk21 so far. You can try to use 5.0-beta1

     import java.net.InetSocketAddress;
    
    import com.datastax.oss.driver.api.core.CqlSession;
    
    import com.github.nosan.embedded.cassandra.Cassandra;
    import com.github.nosan.embedded.cassandra.CassandraBuilder;
    import com.github.nosan.embedded.cassandra.Settings;
    
    class Scratch {
    
        public static void main(String[] args) {
            Cassandra cassandra = new CassandraBuilder()
                    .version("5.0-beta1")
                    .addSystemProperty("java.security.manager", "allow").build();
    
            cassandra.start();
            try {
                Settings settings = cassandra.getSettings();
                try (CqlSession session = CqlSession.builder()
                        .addContactPoint(new InetSocketAddress(settings.getAddress(), settings.getPort()))
                        .withLocalDatacenter("datacenter1")
                        .build()) {
                    //
                }
            }
            finally {
                cassandra.stop();
            }
        }
    
    }