maedhroz commented on a change in pull request #1334:
URL: https://github.com/apache/cassandra/pull/1334#discussion_r753449233
##########
File path:
test/distributed/org/apache/cassandra/distributed/test/SecondaryIndexTest.java
##########
@@ -78,31 +80,45 @@ public void after()
}
@Test
- public void test_only_coordinator_chooses_index_for_query() throws
InterruptedException, UnknownHostException
+ public void test_only_coordinator_chooses_index_for_query()
{
for (int i = 0 ; i < 99 ; ++i)
cluster.coordinator(1).execute(String.format("INSERT INTO %s (k,
v) VALUES (?, ?)", tableName), ConsistencyLevel.ALL, i, i/3);
cluster.forEach(i -> i.flush(KEYSPACE));
- for (int i = 0 ; i < 33 ; ++i)
+ Pattern indexScanningPattern =
+ Pattern.compile(String.format("Index mean cardinalities are
v_index_%d:[0-9]+. Scanning with v_index_%d.", seq.get(), seq.get()));
+
+ for (int i = 0 ; i < 33; ++i)
{
UUID trace = UUID.randomUUID();
Object[][] result =
cluster.coordinator(1).executeWithTracing(trace, String.format("SELECT * FROM
%s WHERE v = ?", tableName), ConsistencyLevel.ALL, i);
- Assert.assertEquals(3, result.length);
- Thread.sleep(100L);
- Object[][] traces =
cluster.coordinator(1).execute(String.format("SELECT source, activity FROM
system_traces.events WHERE session_id = ?", tableName), ConsistencyLevel.ALL,
trace);
- List<InetAddress> scanning = Arrays.stream(traces)
- .filter(t ->
t[1].toString().matches("Index mean cardinalities are v_index:[0-9]+. Scanning
with v_index."))
- .map(t -> (InetAddress) t[0])
-
.distinct().collect(Collectors.toList());
-
- List<InetAddress> executing = Arrays.stream(traces)
- .filter(t ->
t[1].toString().equals("Executing read on " + tableName + " using index
v_index"))
- .map(t -> (InetAddress) t[0])
-
.distinct().collect(Collectors.toList());
-
-
Assert.assertEquals(Collections.singletonList(cluster.get(1).broadcastAddress().getAddress()),
scanning);
- Assert.assertEquals(3, executing.size());
+ Assert.assertEquals("Failed on iteration " + i, 3, result.length);
+
+ Awaitility.await("For all events in the tracing session to
persist")
+ .pollInterval(100, TimeUnit.MILLISECONDS)
+ .atMost(10, TimeUnit.SECONDS)
+ .untilAsserted(() ->
+ {
+ Object[][] traces =
cluster.coordinator(1)
+
.execute("SELECT source, activity FROM system_traces.events WHERE session_id =
?",
+
ConsistencyLevel.ALL, trace);
+
+ List<InetAddress> scanning =
+ Arrays.stream(traces)
+ .filter(t ->
indexScanningPattern.matcher(t[1].toString()).matches())
+ .map(t -> (InetAddress)
t[0])
+
.distinct().collect(Collectors.toList());
+
+ List<InetAddress> executing =
+ Arrays.stream(traces)
+ .filter(t ->
t[1].toString().equals(String.format("Executing read on " + tableName + " using
index v_index_%d", seq.get())))
+ .map(t -> (InetAddress)
t[0])
+
.distinct().collect(Collectors.toList());
+
+
Assert.assertEquals(Collections.singletonList(cluster.get(1).broadcastAddress().getAddress()),
scanning);
+ Assert.assertEquals(3,
executing.size());
+ });
Review comment:
It might also have been possible to make some changes to the actual
Tracing implementation to force pending events to persist, but it seemed
cleaner to just keep changes isolated to the test.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]