DATACASS-429 - Assert compatibility with Duration type.

We now test compatibility with Apache Cassandra's duration type (introduced with Apache Cassandra 3.10). Duration requires a driver version >= 3.2.0 so we drop build profiles against earlier driver versions and use Apache Cassandra 3.10 for integration tests.
This commit is contained in:
Mark Paluch
2017-04-19 11:43:52 +02:00
parent dfc53b635a
commit 0ff0f2348b
5 changed files with 58 additions and 24 deletions

View File

@@ -5,10 +5,9 @@ jdk:
env:
global:
- CASSANDRA_VERSION=3.9
- CASSANDRA_VERSION=3.10
matrix:
- PROFILE=ci
- PROFILE=ci CASSANDRA_DRIVER_VERSION=3.0.3
- PROFILE=spring42
- PROFILE=spring43
- PROFILE=spring43-next

View File

@@ -90,7 +90,7 @@
<build.cassandra.rpc_port>19160</build.cassandra.rpc_port>
<build.cassandra.ssl_storage_port>17001</build.cassandra.ssl_storage_port>
<build.cassandra.storage_port>17000</build.cassandra.storage_port>
<cassandra.version>3.9</cassandra.version>
<cassandra.version>3.10</cassandra.version>
<cassandra-driver.version>3.2.0</cassandra-driver.version>
<dist.id>spring-data-cassandra</dist.id>
<el.version>1.0</el.version>

View File

@@ -86,15 +86,9 @@ public class CreateUserTypeCqlGeneratorIntegrationTests extends AbstractKeyspace
CreateUserTypeSpecification personSpec = CreateUserTypeSpecification //
.createType() //
.name("person").ifNotExists().field("address", address) //
.name("person").ifNotExists().field("address", address.copy(true)) //
.field("city", DataType.varchar());
// Cassandra driver compatibility code: driver 3.0.x for frozen UDT in UDT types.
String cql = toCql(personSpec);
if (!cql.contains("frozen<") && !cql.contains(".address>")) {
cql = cql.replaceAll("address .*\\.address", "address frozen<address>");
}
session.execute(cql);
session.execute(toCql(personSpec));
}
}

View File

@@ -186,6 +186,7 @@ class EmbeddedCassandraServerHelper {
private static void cleanupAndRecreateDirectories() throws IOException {
DatabaseDescriptor.daemonInitialization();
createCassandraDirectories();
cleanup();
createCassandraDirectories();

View File

@@ -16,6 +16,10 @@
package org.springframework.data.cassandra.convert;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.math.BigDecimal;
import java.math.BigInteger;
@@ -33,11 +37,15 @@ import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
import org.springframework.data.annotation.Id;
import org.springframework.data.cassandra.core.CassandraOperations;
import org.springframework.data.cassandra.core.CassandraTemplate;
import org.springframework.data.cassandra.domain.AllPossibleTypes;
import org.springframework.data.cassandra.test.integration.support.CassandraVersion;
import org.springframework.data.cassandra.test.integration.support.SchemaTestUtils;
import org.springframework.data.util.Version;
import com.datastax.driver.core.Duration;
import com.datastax.driver.core.LocalDate;
import com.datastax.driver.core.SimpleStatement;
@@ -50,18 +58,28 @@ import com.datastax.driver.core.SimpleStatement;
@SuppressWarnings("Since15")
public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest {
static final Version VERSION_3_1 = Version.parse("3.10");
CassandraOperations operations;
Version cassandraVersion;
@Before
public void before() {
operations = new CassandraTemplate(session);
cassandraVersion = CassandraVersion.get(session);
SchemaTestUtils.potentiallyCreateTableFor(AllPossibleTypes.class, operations);
SchemaTestUtils.potentiallyCreateTableFor(TimeEntity.class, operations);
SchemaTestUtils.truncate(AllPossibleTypes.class, operations);
SchemaTestUtils.truncate(TimeEntity.class, operations);
if (cassandraVersion.isGreaterThanOrEqualTo(VERSION_3_1)) {
SchemaTestUtils.potentiallyCreateTableFor(WithDuration.class, operations);
SchemaTestUtils.truncate(WithDuration.class, operations);
}
}
@Test // DATACASS-280
@@ -444,7 +462,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteLocalDate() throws Exception {
public void shouldReadAndWriteLocalDate() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setLocalDate(java.time.LocalDate.of(2010, 7, 4));
@@ -456,7 +474,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteLocalDateTime() throws Exception {
public void shouldReadAndWriteLocalDateTime() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setLocalDateTime(java.time.LocalDateTime.of(2010, 7, 4, 1, 2, 3));
@@ -468,7 +486,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteLocalTime() throws Exception {
public void shouldReadAndWriteLocalTime() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setLocalTime(java.time.LocalTime.of(1, 2, 3));
@@ -480,7 +498,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteInstant() throws Exception {
public void shouldReadAndWriteInstant() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setInstant(java.time.Instant.now());
@@ -492,7 +510,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteZoneId() throws Exception {
public void shouldReadAndWriteZoneId() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setZoneId(java.time.ZoneId.of("Europe/Paris"));
@@ -504,7 +522,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteJodaLocalDate() throws Exception {
public void shouldReadAndWriteJodaLocalDate() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setJodaLocalDate(new org.joda.time.LocalDate(2010, 7, 4));
@@ -516,7 +534,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteJodaDateMidnight() throws Exception {
public void shouldReadAndWriteJodaDateMidnight() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setJodaDateMidnight(new org.joda.time.DateMidnight(2010, 7, 4));
@@ -528,7 +546,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteJodaDateTime() throws Exception {
public void shouldReadAndWriteJodaDateTime() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setJodaDateTime(new org.joda.time.DateTime(2010, 7, 4, 1, 2, 3));
@@ -540,7 +558,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteBpLocalDate() throws Exception {
public void shouldReadAndWriteBpLocalDate() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setBpLocalDate(org.threeten.bp.LocalDate.of(2010, 7, 4));
@@ -552,7 +570,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteBpLocalDateTime() throws Exception {
public void shouldReadAndWriteBpLocalDateTime() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setBpLocalDateTime(org.threeten.bp.LocalDateTime.of(2010, 7, 4, 1, 2, 3));
@@ -564,7 +582,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteBpLocalTime() throws Exception {
public void shouldReadAndWriteBpLocalTime() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setBpLocalTime(org.threeten.bp.LocalTime.of(1, 2, 3));
@@ -576,7 +594,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteBpInstant() throws Exception {
public void shouldReadAndWriteBpInstant() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setBpInstant(org.threeten.bp.Instant.now());
@@ -588,7 +606,7 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
}
@Test // DATACASS-296
public void shouldReadAndWriteBpZoneId() throws Exception {
public void shouldReadAndWriteBpZoneId() {
AllPossibleTypes entity = new AllPossibleTypes("1");
entity.setBpZoneId(org.threeten.bp.ZoneId.of("Europe/Paris"));
@@ -612,6 +630,20 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
assertThat(loaded.getCount()).isEqualTo(entity.getCount());
}
@Test // DATACASS-429
public void shouldReadAndWriteDuration() {
assumeTrue(cassandraVersion.isGreaterThanOrEqualTo(VERSION_3_1));
WithDuration withDuration = new WithDuration("foo", Duration.from("2h"));
operations.insert(withDuration);
WithDuration loaded = operations.selectOneById(withDuration.getId(), WithDuration.class);
assertThat(loaded.getDuration()).isEqualTo(withDuration.getDuration());
}
private AllPossibleTypes load(AllPossibleTypes entity) {
return operations.selectOneById(entity.getId(), AllPossibleTypes.class);
}
@@ -619,4 +651,12 @@ public class CassandraTypeMappingIntegrationTest extends AbstractKeyspaceCreatin
public enum Condition {
MINT
}
@Data
@AllArgsConstructor
static class WithDuration {
@Id String id;
Duration duration;
}
}