Skip to content

Commit e4744a7

Browse files
llinderadriancole
authored andcommitted
Uses docker for C* tests (openzipkin#1573)
1 parent d7cdf7d commit e4744a7

14 files changed

+482
-315
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<assertj.version>3.8.0</assertj.version>
7171
<hamcrest.version>1.3</hamcrest.version>
7272
<okhttp.version>3.8.0</okhttp.version>
73-
<testcontainers.version>1.3.0</testcontainers.version>
73+
<testcontainers.version>1.3.1</testcontainers.version>
7474

7575
<animal-sniffer-maven-plugin.version>1.15</animal-sniffer-maven-plugin.version>
7676
<maven-compiler-plugin.version>3.6.1</maven-compiler-plugin.version>

zipkin-storage/cassandra3/pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,12 @@
7878
<version>${logback.version}</version>
7979
<scope>test</scope>
8080
</dependency>
81+
82+
<dependency>
83+
<groupId>org.testcontainers</groupId>
84+
<artifactId>testcontainers</artifactId>
85+
<scope>test</scope>
86+
</dependency>
87+
8188
</dependencies>
8289
</project>

zipkin-storage/cassandra3/src/main/java/zipkin/storage/cassandra3/Cassandra3Storage.java

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,13 @@
1717
import com.datastax.driver.core.querybuilder.QueryBuilder;
1818
import com.google.common.annotations.VisibleForTesting;
1919
import com.google.common.collect.ImmutableList;
20-
import com.google.common.util.concurrent.Futures;
21-
import com.google.common.util.concurrent.ListenableFuture;
2220
import java.io.IOException;
23-
import java.util.LinkedList;
24-
import java.util.List;
2521
import zipkin.internal.LazyCloseable;
2622
import zipkin.internal.Nullable;
2723
import zipkin.storage.QueryRequest;
2824
import zipkin.storage.StorageComponent;
2925
import zipkin.storage.guava.LazyGuavaStorageComponent;
3026

31-
import static java.lang.String.format;
3227
import static zipkin.internal.Util.checkNotNull;
3328

3429
/**
@@ -234,15 +229,13 @@ public Session session() {
234229

235230
/** Truncates all the column families, or throws on any failure. */
236231
@VisibleForTesting void clear() {
237-
List<ListenableFuture<?>> futures = new LinkedList<>();
238232
for (String cf : ImmutableList.of(
239-
Schema.TABLE_TRACES,
240-
Schema.TABLE_TRACE_BY_SERVICE_SPAN,
241-
Schema.TABLE_SERVICE_SPANS,
242-
Schema.TABLE_DEPENDENCIES
233+
Schema.TABLE_TRACES,
234+
Schema.TABLE_TRACE_BY_SERVICE_SPAN,
235+
Schema.TABLE_SERVICE_SPANS,
236+
Schema.TABLE_DEPENDENCIES
243237
)) {
244-
futures.add(session.get().executeAsync(format("TRUNCATE %s", cf)));
238+
session.get().execute("TRUNCATE " + cf);
245239
}
246-
Futures.getUnchecked(Futures.allAsList(futures));
247240
}
248241
}

zipkin-storage/cassandra3/src/test/java/zipkin/storage/cassandra3/Cassandra3TestGraph.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

zipkin-storage/cassandra3/src/test/java/zipkin/storage/cassandra3/CassandraDependenciesTest.java

Lines changed: 0 additions & 106 deletions
This file was deleted.

zipkin-storage/cassandra3/src/test/java/zipkin/storage/cassandra3/EnsureSchemaTest.java

Lines changed: 0 additions & 81 deletions
This file was deleted.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright 2015-2017 The OpenZipkin Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package zipkin.storage.cassandra3;
15+
16+
import com.datastax.driver.core.KeyspaceMetadata;
17+
import com.datastax.driver.core.Session;
18+
import com.datastax.driver.core.Statement;
19+
import com.datastax.driver.core.policies.RetryPolicy;
20+
import com.datastax.driver.core.querybuilder.QueryBuilder;
21+
import java.nio.ByteBuffer;
22+
import java.util.Date;
23+
import java.util.List;
24+
import zipkin.Codec;
25+
import zipkin.DependencyLink;
26+
import zipkin.storage.AsyncSpanConsumer;
27+
28+
import static zipkin.storage.guava.GuavaStorageAdapters.guavaToAsync;
29+
30+
public class InternalForTests {
31+
32+
public static void clear(Cassandra3Storage storage) {
33+
storage.clear();
34+
}
35+
36+
public static void writeDependencyLinks(Cassandra3Storage storage, List<DependencyLink> links,
37+
long midnightUTC) {
38+
39+
ByteBuffer thrift = ByteBuffer.wrap(Codec.THRIFT.writeDependencyLinks(links));
40+
41+
Date startFlooredToDay = new Date(midnightUTC);
42+
Statement statement = QueryBuilder.insertInto(Schema.TABLE_DEPENDENCIES)
43+
.value("day", startFlooredToDay)
44+
.value("links", thrift);
45+
46+
storage.session().execute(statement);
47+
}
48+
49+
public static int indexFetchMultiplier(Cassandra3Storage storage) {
50+
return storage.indexFetchMultiplier;
51+
}
52+
53+
public static long rowCountForTraceByServiceSpan(Cassandra3Storage storage) {
54+
return rowCount(storage, Schema.TABLE_TRACE_BY_SERVICE_SPAN);
55+
}
56+
57+
public static AsyncSpanConsumer withoutStrictTraceId(Cassandra3Storage storage) {
58+
return guavaToAsync(new CassandraSpanConsumer(storage.session(), false));
59+
}
60+
61+
public static KeyspaceMetadata ensureExists(String keyspace, Session session) {
62+
return Schema.ensureExists(keyspace, session);
63+
}
64+
65+
public static RetryPolicy zipkinRetryPolicy() {
66+
return ZipkinRetryPolicy.INSTANCE;
67+
}
68+
69+
private static long rowCount(Cassandra3Storage storage, String table) {
70+
return storage.session().execute("SELECT COUNT(*) from " + table).one().getLong(0);
71+
}
72+
}

0 commit comments

Comments
 (0)