Skip to content

Commit ff4e003

Browse files
authored
JAVA-3076: NullSavingStrategyIT sometimes fails with ProtocolError: Must not send frame with WARNING flag for native protocol version < 4 (#1669)
NullSavingStrategyIT.java: - Remove V3 protocol configuration from class SessionRule - Create new session configured with V3 protocol in @BeforeClass method to use in tests
1 parent fd446ce commit ff4e003

File tree

1 file changed

+48
-15
lines changed

1 file changed

+48
-15
lines changed

integration-tests/src/test/java/com/datastax/oss/driver/mapper/NullSavingStrategyIT.java

Lines changed: 48 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
import com.datastax.oss.driver.api.mapper.entity.saving.NullSavingStrategy;
3737
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
3838
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
39+
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
3940
import com.datastax.oss.driver.categories.ParallelizableTests;
4041
import java.util.Objects;
4142
import java.util.UUID;
43+
import org.junit.AfterClass;
4244
import org.junit.BeforeClass;
4345
import org.junit.ClassRule;
4446
import org.junit.Test;
@@ -51,13 +53,24 @@ public class NullSavingStrategyIT {
5153

5254
private static final CcmRule CCM_RULE = CcmRule.getInstance();
5355

54-
private static final SessionRule<CqlSession> SESSION_RULE =
55-
SessionRule.builder(CCM_RULE)
56-
.withConfigLoader(
57-
DriverConfigLoader.programmaticBuilder()
58-
.withString(DefaultDriverOption.PROTOCOL_VERSION, "V3")
59-
.build())
60-
.build();
56+
private static final SessionRule<CqlSession> SESSION_RULE = SessionRule.builder(CCM_RULE).build();
57+
58+
// JAVA-3076: V3 protocol calls that could trigger cassandra to issue client warnings appear to be
59+
// inherently unstable when used at the same time as V4+ protocol clients (common since this is
60+
// part of the parallelizable test suite).
61+
//
62+
// For this test we'll use latest protocol version for SessionRule set-up, which creates the
63+
// keyspace and could potentially result in warning about too many keyspaces, and then create a
64+
// new client for the tests to use, which they access via the static InventoryMapper instance
65+
// `mapper`.
66+
//
67+
// This additional client is created in the @BeforeClass method #setup() and guaranteed to be
68+
// closed in @AfterClass method #teardown().
69+
//
70+
// Note: The standard junit runner executes rules before class/test setup so the order of
71+
// execution will be CcmRule#before > SessionRule#before > NullSavingStrategyIT#setup, meaning
72+
// CCM_RULE/SESSION_RULE should be fully initialized by the time #setup() is invoked.
73+
private static CqlSession v3Session;
6174

6275
@ClassRule
6376
public static final TestRule CHAIN = RuleChain.outerRule(CCM_RULE).around(SESSION_RULE);
@@ -66,14 +79,34 @@ public class NullSavingStrategyIT {
6679

6780
@BeforeClass
6881
public static void setup() {
69-
CqlSession session = SESSION_RULE.session();
70-
session.execute(
71-
SimpleStatement.builder(
72-
"CREATE TABLE product_simple(id uuid PRIMARY KEY, description text)")
73-
.setExecutionProfile(SESSION_RULE.slowProfile())
74-
.build());
75-
76-
mapper = new NullSavingStrategyIT_InventoryMapperBuilder(session).build();
82+
// setup table for use in tests, this can use the default session
83+
SESSION_RULE
84+
.session()
85+
.execute(
86+
SimpleStatement.builder(
87+
"CREATE TABLE product_simple(id uuid PRIMARY KEY, description text)")
88+
.setExecutionProfile(SESSION_RULE.slowProfile())
89+
.build());
90+
91+
// Create V3 protocol session for use in tests, will be closed in #teardown()
92+
v3Session =
93+
SessionUtils.newSession(
94+
CCM_RULE,
95+
SESSION_RULE.keyspace(),
96+
DriverConfigLoader.programmaticBuilder()
97+
.withString(DefaultDriverOption.PROTOCOL_VERSION, "V3")
98+
.build());
99+
100+
// Hand V3 session to InventoryMapper which the tests will use to perform db calls
101+
mapper = new NullSavingStrategyIT_InventoryMapperBuilder(v3Session).build();
102+
}
103+
104+
@AfterClass
105+
public static void teardown() {
106+
// Close V3 session (SESSION_RULE will be closed separately by @ClassRule handling)
107+
if (v3Session != null) {
108+
v3Session.close();
109+
}
77110
}
78111

79112
@Test

0 commit comments

Comments
 (0)