7
7
import static org .mockito .Mockito .atLeast ;
8
8
import static org .mockito .Mockito .atMost ;
9
9
import static org .mockito .Mockito .mock ;
10
- import static org .mockito .Mockito .times ;
11
10
import static org .mockito .Mockito .verify ;
12
11
13
12
import com .datastax .driver .core .utils .ScyllaOnly ;
13
+ import java .util .ArrayList ;
14
14
import java .util .Collection ;
15
15
import org .testng .annotations .Test ;
16
16
19
19
public class ScyllaSniProxyTest extends CCMTestsSupport {
20
20
21
21
private void test_ccm_cluster (int testNodes ) {
22
+ ccm ().setKeepLogs (true );
22
23
Cluster c = cluster ().init ();
23
24
Session s = c .connect ();
24
25
TestUtils .waitForUp (TestUtils .ipOfNode (1 ), c );
@@ -35,15 +36,60 @@ private void test_ccm_cluster(int testNodes) {
35
36
((SessionManager ) s ).cluster .manager .controlConnection .triggerReconnect ();
36
37
37
38
SchemaChangeListener listener = mock (SchemaChangeListenerBase .class );
39
+ final ArrayList <String > keyspaceMismatches = new ArrayList <String >();
40
+ final ArrayList <String > tableMismatches = new ArrayList <String >();
41
+
42
+ SchemaChangeListener assertingListener =
43
+ new SchemaChangeListenerBase () {
44
+ @ Override
45
+ public void onKeyspaceAdded (KeyspaceMetadata keyspace ) {
46
+ if (!keyspace .getName ().equals ("testks" )) {
47
+ keyspaceMismatches .add (keyspace .getName ());
48
+ }
49
+ }
50
+
51
+ @ Override
52
+ public void onTableAdded (TableMetadata table ) {
53
+ if (!table .getName ().equals ("testtab" )) {
54
+ tableMismatches .add (table .getName ());
55
+ }
56
+ }
57
+ };
58
+
38
59
c .register (listener );
60
+ c .register (assertingListener );
39
61
40
62
s .execute (String .format (TestUtils .CREATE_KEYSPACE_SIMPLE_FORMAT , "testks" , testNodes ));
41
63
s .execute ("CREATE TABLE testks.testtab (a int PRIMARY KEY, b int);" );
42
64
43
- verify (listener , times (1 )).onTableAdded (any (TableMetadata .class ));
65
+ // Sometimes (probably due to reconnection) both events can be read twice
66
+ // assertingListener ensures we deal with the same keyspace and table
67
+ verify (listener , atLeast (1 )).onTableAdded (any (TableMetadata .class ));
68
+ verify (listener , atMost (2 )).onTableAdded (any (TableMetadata .class ));
44
69
verify (listener , atLeast (1 )).onKeyspaceAdded (any (KeyspaceMetadata .class ));
45
70
verify (listener , atMost (2 )).onKeyspaceAdded (any (KeyspaceMetadata .class ));
46
71
72
+ if (!keyspaceMismatches .isEmpty ()) {
73
+ StringBuilder ksNames = new StringBuilder ();
74
+ for (String str : keyspaceMismatches ) {
75
+ ksNames .append (", " + ksNames + str );
76
+ }
77
+ throw new RuntimeException (
78
+ "assertingListener registered keyspace added event with keyspaces named: ["
79
+ + ksNames .substring (2 )
80
+ + "] which is not \" testks\" " );
81
+ }
82
+ if (!tableMismatches .isEmpty ()) {
83
+ StringBuilder tabNames = new StringBuilder ();
84
+ for (String str : tableMismatches ) {
85
+ tabNames .append (", " + tabNames + str );
86
+ }
87
+ throw new RuntimeException (
88
+ "assertingListener registered table added event with tables named: ["
89
+ + tabNames .substring (2 )
90
+ + "] which is not \" testtab\" " );
91
+ }
92
+
47
93
s .close ();
48
94
c .close ();
49
95
}
0 commit comments