if (NO_VERSION.equals(requiredVersion)) { return; Version runningVersion = Version.parse(redisVersion); if (runningVersion.isLessThan(requiredVersion)) { throw new AssumptionViolatedException(String .format("This test requires Redis version %s but you run version %s", requiredVersion, runningVersion));
/** * Create a {@link CassandraKeyspace} test rule to provide a running Cassandra instance on {@code localhost:9042} with * a keyspace {@code example}. Reuses a running Cassandra instance if available or starts an embedded instance. * * @return the {@link CassandraKeyspace} rule. */ public static CassandraKeyspace onLocalhost() { return new CassandraKeyspace("localhost", ProtocolOptions.DEFAULT_PORT, "example", Cassandra.embeddedIfNotRunning("localhost", ProtocolOptions.DEFAULT_PORT), new Version(0, 0, 0)); }
/** * Require a specific Redis version. * * @param version must not be {@literal null} or empty. * @return */ public RequiresRedisServer atLeast(String version) { Assert.hasText(version, "Version must not be empty!"); return new RequiresRedisServer(host, port, Version.parse(version)); }
@Override protected void before() throws Throwable { dependency.before(); 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(); } }
/** * Returns whether the current {@link Version} is the same as the given one. * * @param version * @return */ public boolean is(Version version) { return equals(version); }
/** * Returns whether the current {@link Version} is greater (newer) or the same as the given one. * * @param version * @return */ public boolean isGreaterThanOrEqualTo(Version version) { return compareTo(version) >= 0; }
/** * Retrieve the Cassandra release version. * * @param session must not be {@literal null}. * @return the release {@link Version}. */ public static Version getReleaseVersion(Session session) { Assert.notNull(session, "Session must not be null"); ResultSet resultSet = session.execute("SELECT release_version FROM system.local;"); Row row = resultSet.one(); return Version.parse(row.getString(0)); } }
/** * Returns whether the current {@link Version} is greater (newer) than the given one. * * @param version * @return */ public boolean isGreaterThan(Version version) { return compareTo(version) > 0; }
/** * Returns the Java version of the running JVM. * * @return will never be {@literal null}. */ public static Version javaVersion() { return parse(System.getProperty("java.version")); }
/** * Parses the given string representation of a version into a {@link Version} object. * * @param version must not be {@literal null} or empty. * @return */ public static Version parse(String version) { Assert.hasText(version, "Version must not be null o empty!"); String[] parts = version.trim().split("\\."); int[] intParts = new int[parts.length]; for (int i = 0; i < parts.length; i++) { String input = i == parts.length - 1 ? parts[i].replaceAll("\\D.*", "") : parts[i]; if (StringUtils.hasText(input)) { try { intParts[i] = Integer.parseInt(input); } catch (IllegalArgumentException o_O) { throw new IllegalArgumentException(String.format(VERSION_PARSE_ERROR, input, version), o_O); } } } return new Version(intParts); }
/** * Returns whether the current {@link Version} is less (older) than the given one. * * @param version * @return */ public boolean isLessThan(Version version) { return compareTo(version) < 0; }
/** * Returns whether the current {@link Version} is less (older) or equal to the current one. * * @param version * @return */ public boolean isLessThanOrEqualTo(Version version) { return compareTo(version) <= 0; }