Skip to content

Commit 5d1b0ff

Browse files
author
Michael Karsten
committed
test: add integration test
1 parent cd1127b commit 5d1b0ff

File tree

1 file changed

+136
-0
lines changed

1 file changed

+136
-0
lines changed
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package com.datastax.oss.driver.querybuilder;
19+
20+
import static org.assertj.core.api.Assertions.assertThat;
21+
22+
import com.datastax.oss.driver.api.core.CqlSession;
23+
import com.datastax.oss.driver.api.core.config.DefaultDriverOption;
24+
import com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata;
25+
import com.datastax.oss.driver.api.core.type.DataTypes;
26+
import com.datastax.oss.driver.api.querybuilder.SchemaBuilder;
27+
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
28+
import com.datastax.oss.driver.api.testinfra.requirement.BackendRequirement;
29+
import com.datastax.oss.driver.api.testinfra.requirement.BackendType;
30+
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
31+
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
32+
import com.datastax.oss.driver.categories.ParallelizableTests;
33+
import java.time.Duration;
34+
35+
import org.junit.After;
36+
import org.junit.ClassRule;
37+
import org.junit.Test;
38+
import org.junit.experimental.categories.Category;
39+
import org.junit.rules.RuleChain;
40+
import org.junit.rules.TestRule;
41+
42+
@Category(ParallelizableTests.class)
43+
public class RelationOptionsIT {
44+
private static final CcmRule CCM_RULE = CcmRule.getInstance();
45+
46+
private static final SessionRule<CqlSession> SESSION_RULE =
47+
SessionRule.builder(CCM_RULE)
48+
.withConfigLoader(
49+
SessionUtils.configLoaderBuilder()
50+
.withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(30))
51+
.build())
52+
.build();
53+
54+
@ClassRule
55+
public static final TestRule CHAIN = RuleChain.outerRule(CCM_RULE).around(SESSION_RULE);
56+
57+
@After
58+
public void clearTable() {
59+
SESSION_RULE.session().execute("DROP TABLE relation_options");
60+
}
61+
62+
@Test
63+
@BackendRequirement(
64+
type = BackendType.CASSANDRA,
65+
minInclusive = "3.0",
66+
description = "CRC check chance was moved to top level table in Cassandra 3.0")
67+
public void should_create_table_with_crc_check_chance() {
68+
try (CqlSession session = session()) {
69+
session.execute(SchemaBuilder.createTable("relation_options")
70+
.withPartitionKey("id", DataTypes.INT)
71+
.withColumn("name", DataTypes.TEXT)
72+
.withColumn("age", DataTypes.INT)
73+
.withCRCCheckChance(0.8)
74+
.build());
75+
KeyspaceMetadata keyspaceMetadata =
76+
session.getMetadata().getKeyspace(SESSION_RULE.keyspace()).orElseThrow(AssertionError::new);
77+
String describeOutput = keyspaceMetadata.describeWithChildren(true).trim();
78+
79+
assertThat(describeOutput).contains("crc_check_chance = 0.8");
80+
}
81+
}
82+
83+
@Test
84+
@BackendRequirement(
85+
type = BackendType.CASSANDRA,
86+
minInclusive = "5.0",
87+
description = "chunk_length_kb was renamed to chunk_length_in_kb in Cassandra 5.0")
88+
public void should_create_table_with_chunk_length_in_kb() {
89+
try (CqlSession session = session()) {
90+
session.execute(SchemaBuilder.createTable("relation_options")
91+
.withPartitionKey("id", DataTypes.INT)
92+
.withColumn("name", DataTypes.TEXT)
93+
.withColumn("age", DataTypes.INT)
94+
.withLZ4Compression(4096)
95+
.build());
96+
KeyspaceMetadata keyspaceMetadata =
97+
session.getMetadata().getKeyspace(SESSION_RULE.keyspace()).orElseThrow(AssertionError::new);
98+
String describeOutput = keyspaceMetadata.describeWithChildren(true).trim();
99+
100+
assertThat(describeOutput).contains("'class':'org.apache.cassandra.io.compress.LZ4Compressor'");
101+
assertThat(describeOutput).contains("'chunk_length_in_kb':'4096'");
102+
}
103+
}
104+
105+
@Test
106+
@BackendRequirement(
107+
type = BackendType.CASSANDRA,
108+
maxExclusive = "5.0",
109+
description = "chunk_length_kb was renamed to chunk_length_in_kb in Cassandra 5.0")
110+
public void should_create_table_with_deprecated_options() {
111+
try (CqlSession session = session()) {
112+
session.execute(SchemaBuilder.createTable("relation_options")
113+
.withPartitionKey("id", DataTypes.INT)
114+
.withColumn("name", DataTypes.TEXT)
115+
.withColumn("age", DataTypes.INT)
116+
.withLZ4Compression(4096, 1.0)
117+
.build());
118+
KeyspaceMetadata keyspaceMetadata =
119+
session.getMetadata().getKeyspace(SESSION_RULE.keyspace()).orElseThrow(AssertionError::new);
120+
String describeOutput = keyspaceMetadata.describeWithChildren(true).trim();
121+
122+
assertThat(describeOutput).contains("'class':'org.apache.cassandra.io.compress.LZ4Compressor'");
123+
assertThat(describeOutput).contains("'chunk_length_kb':'4096'");
124+
assertThat(describeOutput).contains("'crc_check_chance':'0.8'");
125+
}
126+
}
127+
128+
@SuppressWarnings("unchecked")
129+
private CqlSession session() {
130+
return (CqlSession)
131+
SessionUtils.baseBuilder()
132+
.addContactEndPoints(CCM_RULE.getContactPoints())
133+
.withKeyspace(SESSION_RULE.keyspace())
134+
.build();
135+
}
136+
}

0 commit comments

Comments
 (0)