36
36
import com .datastax .oss .driver .api .mapper .entity .saving .NullSavingStrategy ;
37
37
import com .datastax .oss .driver .api .testinfra .ccm .CcmRule ;
38
38
import com .datastax .oss .driver .api .testinfra .session .SessionRule ;
39
+ import com .datastax .oss .driver .api .testinfra .session .SessionUtils ;
39
40
import com .datastax .oss .driver .categories .ParallelizableTests ;
40
41
import java .util .Objects ;
41
42
import java .util .UUID ;
43
+ import org .junit .AfterClass ;
42
44
import org .junit .BeforeClass ;
43
45
import org .junit .ClassRule ;
44
46
import org .junit .Test ;
@@ -51,13 +53,24 @@ public class NullSavingStrategyIT {
51
53
52
54
private static final CcmRule CCM_RULE = CcmRule .getInstance ();
53
55
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 ;
61
74
62
75
@ ClassRule
63
76
public static final TestRule CHAIN = RuleChain .outerRule (CCM_RULE ).around (SESSION_RULE );
@@ -66,14 +79,34 @@ public class NullSavingStrategyIT {
66
79
67
80
@ BeforeClass
68
81
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
+ }
77
110
}
78
111
79
112
@ Test
0 commit comments