List of usage examples for org.springframework.data.util Version isLessThan
public boolean isLessThan(Version version)
From source file:example.springdata.cassandra.util.RequiresCassandraKeyspace.java
@Override protected void before() throws Throwable { try (Socket socket = new Socket()) { socket.setTcpNoDelay(true);//from w w w . jav a2 s. com socket.setSoLinger(true, 0); socket.connect(new InetSocketAddress(host, port), timeout); } catch (Exception e) { throw new AssumptionViolatedException( String.format("Seems as Cassandra is not running at %s:%s.", host, port), e); } Cluster cluster = Cluster.builder().addContactPoint(host).withPort(port) .withNettyOptions(new NettyOptions() { @Override public void onClusterClose(EventLoopGroup eventLoopGroup) { eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly(); } }).build(); Session session = cluster.newSession(); try { if (requiresVersion != null) { Version cassandraReleaseVersion = CassandraVersion.getReleaseVersion(session); if (cassandraReleaseVersion.isLessThan(requiresVersion)) { throw new AssumptionViolatedException( String.format("Cassandra at %s:%s runs in Version %s but we require at least %s", host, port, cassandraReleaseVersion, requiresVersion)); } } session.execute(String.format( "CREATE KEYSPACE IF NOT EXISTS %s \n" + "WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", keyspaceName)); } finally { session.close(); cluster.close(); } }
From source file:example.springdata.cassandra.util.CassandraKeyspace.java
@Override protected void before() throws Throwable { dependency.before();/*from www. j av a 2s .c om*/ Cluster cluster = Cluster.builder().addContactPoint(getHost()).withPort(getPort()) .withNettyOptions(new NettyOptions() { @Override public void onClusterClose(EventLoopGroup eventLoopGroup) { eventLoopGroup.shutdownGracefully(0, 0, TimeUnit.MILLISECONDS).syncUninterruptibly(); } }).build(); Session session = cluster.newSession(); try { if (requiredVersion != null) { Version cassandraReleaseVersion = CassandraVersion.getReleaseVersion(session); if (cassandraReleaseVersion.isLessThan(requiredVersion)) { throw new AssumptionViolatedException( String.format("Cassandra at %s:%s runs in Version %s but we require at least %s", getHost(), getPort(), cassandraReleaseVersion, requiredVersion)); } } session.execute(String.format( "CREATE KEYSPACE IF NOT EXISTS %s \n" + "WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 1 };", keyspaceName)); } finally { session.close(); cluster.close(); } }