hosts) {
176 |
177 | StringBuilder sb = new StringBuilder();
178 | String delimiter = "";
179 |
180 | for (String key : hosts.keySet()) {
181 | Host host = hosts.get(key);
182 | if (host != null) {
183 | sb.append(delimiter)
184 | .append(host.toString())
185 | .append(" (dc=")
186 | .append(host.getDatacenter())
187 | .append(" up=")
188 | .append(host.isUp())
189 | .append(")");
190 |
191 | delimiter = "\n";
192 | }
193 | }
194 |
195 | return sb.toString();
196 | }
197 |
198 | private String getKey(Host host) {
199 | return host.getAddress().toString();
200 | }
201 |
202 | /**
203 | * Called when a new node is added to the cluster.
204 | *
205 | * The newly added node should be considered up.
206 | *
207 | * @param host the host that has been newly added.
208 | */
209 | @Override
210 | public void onAdd(Host host) {
211 | String key = getKey(host);
212 | addedHosts.put(key, host);
213 | removedHosts.remove(key);
214 | }
215 |
216 | /**
217 | * Called when a node is determined to be up.
218 | *
219 | * @param host the host that has been detected up.
220 | */
221 | @Override
222 | public void onUp(Host host) {
223 | String key = getKey(host);
224 | upHosts.put(key, host);
225 | downHosts.remove(key);
226 | }
227 |
228 | /**
229 | * Called when a node is determined to be down.
230 | *
231 | * @param host the host that has been detected down.
232 | */
233 | @Override
234 | public void onDown(Host host) {
235 | String key = getKey(host);
236 | downHosts.put(key, host);
237 | upHosts.remove(key);
238 | }
239 |
240 | /**
241 | * Called when a node is removed from the cluster.
242 | *
243 | * @param host the removed host.
244 | */
245 | @Override
246 | public void onRemove(Host host) {
247 | String key = getKey(host);
248 | removedHosts.put(key, host);
249 | addedHosts.remove(key);
250 | }
251 |
252 | @Override
253 | public void onRegister(Cluster cluster) {
254 | }
255 |
256 | @Override
257 | public void onUnregister(Cluster cluster) {
258 | }
259 | }
260 | }
261 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/keyspacebuilder/AlterKeyspace.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.keyspacebuilder;
2 |
3 | /**
4 | * ALTER KEYSPACE CQL3 statement builder
5 | */
6 | public class AlterKeyspace extends KeyspaceBuilderBase {
7 |
8 | AlterKeyspace(String keyspace) {
9 | super(keyspace);
10 | }
11 |
12 | /**
13 | * {@inheritDoc}
14 | */
15 | @Override
16 | public StringBuilder buildQueryString() {
17 | StringBuilder sb = new StringBuilder();
18 |
19 | sb.append("ALTER KEYSPACE ").append(keyspace);
20 | buildReplicationStrategy(sb);
21 | sb.append(" }");
22 |
23 | return sb;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/keyspacebuilder/BuiltKeyspaceStatement.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.keyspacebuilder;
2 |
3 | import com.datastax.driver.core.CodecRegistry;
4 | import com.datastax.driver.core.ProtocolVersion;
5 | import com.datastax.driver.core.RegularStatement;
6 |
7 | import java.nio.ByteBuffer;
8 | import java.util.Map;
9 |
10 | /**
11 | * A built CQL3 keyspace statement
12 | */
13 | public abstract class BuiltKeyspaceStatement extends RegularStatement {
14 |
15 | protected String keyspace;
16 |
17 | protected BuiltKeyspaceStatement(String keyspace) {
18 | this.keyspace = keyspace;
19 | }
20 |
21 | /**
22 | * Builds the CQL3 statement
23 | *
24 | * @return a {@link java.lang.StringBuilder} of the CQL statement
25 | */
26 | public abstract StringBuilder buildQueryString();
27 |
28 | /**
29 | * {@inheritDoc}
30 | */
31 | @Override
32 | public String getQueryString() {
33 | return buildQueryString().toString();
34 | }
35 |
36 | /**
37 | * {@inheritDoc}
38 | */
39 | @Override
40 | public String getQueryString(CodecRegistry codecRegistry) {
41 | return getQueryString();
42 | }
43 |
44 | /**
45 | * {@inheritDoc}
46 | */
47 | @Override
48 | public ByteBuffer[] getValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry) {
49 | return null;
50 | }
51 |
52 | /**
53 | * {@inheritDoc}
54 | */
55 | @Override
56 | public boolean hasValues() {
57 | return false;
58 | }
59 |
60 | /**
61 | * {@inheritDoc}
62 | */
63 | @Override
64 | public boolean hasValues(CodecRegistry codecRegistry) {
65 | return false;
66 | }
67 |
68 | /**
69 | * {@inheritDoc}
70 | */
71 | @Override
72 | public ByteBuffer getRoutingKey(ProtocolVersion protocolVersion, CodecRegistry codecRegistry) {
73 | return null;
74 | }
75 |
76 | /**
77 | * {@inheritDoc}
78 | */
79 | @Override
80 | public String getKeyspace() {
81 | return keyspace;
82 | }
83 |
84 | /**
85 | * {@inheritDoc}
86 | */
87 | @Override
88 | public Map getNamedValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry) {
89 | return null;
90 | }
91 |
92 | /**
93 | * {@inheritDoc}
94 | */
95 | @Override
96 | public boolean usesNamedValues() {
97 | return false;
98 | }
99 |
100 | }
101 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/keyspacebuilder/CreateKeyspace.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.keyspacebuilder;
2 |
3 | /**
4 | * CREATE KEYSPACE CQL3 statement builder
5 | */
6 | public class CreateKeyspace extends KeyspaceBuilderBase {
7 |
8 | private boolean ifNotExists;
9 |
10 | CreateKeyspace(String keyspace) {
11 | super(keyspace);
12 | }
13 |
14 | public CreateKeyspace ifNotExists() {
15 | ifNotExists = true;
16 | return this;
17 | }
18 |
19 | /**
20 | * {@inheritDoc}
21 | */
22 | @Override
23 | public StringBuilder buildQueryString() {
24 | StringBuilder sb = new StringBuilder();
25 |
26 | sb.append("CREATE KEYSPACE ");
27 | if (ifNotExists) {
28 | sb.append("IF NOT EXISTS ");
29 | }
30 | sb.append(keyspace);
31 | buildReplicationStrategy(sb);
32 | sb.append(" }");
33 | return sb;
34 | }
35 |
36 | }
37 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/keyspacebuilder/DropKeyspace.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.keyspacebuilder;
2 |
3 | /**
4 | * DROP KEYSPACE CQL3 statement builder
5 | */
6 | public class DropKeyspace extends BuiltKeyspaceStatement {
7 |
8 | private boolean ifExists;
9 |
10 | DropKeyspace(String keyspace) {
11 | super(keyspace);
12 | }
13 |
14 | public DropKeyspace ifExists() {
15 | ifExists = true;
16 | return this;
17 | }
18 |
19 | /**
20 | * {@inheritDoc}
21 | */
22 | @Override
23 | public StringBuilder buildQueryString() {
24 | StringBuilder sb = new StringBuilder();
25 |
26 | sb.append("DROP KEYSPACE ");
27 | if (ifExists) {
28 | sb.append("IF EXISTS ");
29 | }
30 | sb.append(keyspace);
31 |
32 | return sb;
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/keyspacebuilder/KeyspaceBuilder.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.keyspacebuilder;
2 |
3 | /**
4 | * Static methods to build a CQL3 keyspace statement
5 | */
6 | public class KeyspaceBuilder {
7 |
8 | /**
9 | * Returns a {@link com.englishtown.vertx.cassandra.keyspacebuilder.CreateKeyspace} builder
10 | *
11 | * @param keyspace the keyspace to be created
12 | * @return the create keyspace builder
13 | */
14 | public static CreateKeyspace create(String keyspace) {
15 | return new CreateKeyspace(keyspace);
16 | }
17 |
18 | /**
19 | * Returns a {@link com.englishtown.vertx.cassandra.keyspacebuilder.AlterKeyspace} builder
20 | *
21 | * @param keyspace the keyspace to be altered
22 | * @return the alter keyspace builder
23 | */
24 | public static AlterKeyspace alter(String keyspace) {
25 | return new AlterKeyspace(keyspace);
26 | }
27 |
28 | /**
29 | * Returns a {@link com.englishtown.vertx.cassandra.keyspacebuilder.DropKeyspace} builder
30 | *
31 | * @param keyspace the keyspace to drop
32 | * @return the drop keyspace builder
33 | */
34 | public static DropKeyspace drop(String keyspace) {
35 | return new DropKeyspace(keyspace);
36 | }
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/keyspacebuilder/KeyspaceBuilderBase.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.keyspacebuilder;
2 |
3 | import java.util.LinkedHashMap;
4 | import java.util.Map;
5 |
6 | /**
7 | * Base class for CREATE/ALTER KEYSPACE builders
8 | */
9 | abstract class KeyspaceBuilderBase extends BuiltKeyspaceStatement {
10 |
11 | private String strategy = REPLICATION_STRATEGY_SIMPLE;
12 | private int replicationFactor = 1;
13 | private Map dcReplicationFactors = new LinkedHashMap<>();
14 |
15 | public static final String REPLICATION_STRATEGY_SIMPLE = "SimpleStrategy";
16 | public static final String REPLICATION_STRATEGY_NETWORK_TOPOLOGY = "NetworkTopologyStrategy";
17 |
18 | protected KeyspaceBuilderBase(String keyspace) {
19 | super(keyspace);
20 | }
21 |
22 | public KeyspaceBuilderBase simpleStrategy(int replicationFactor) {
23 | strategy = REPLICATION_STRATEGY_SIMPLE;
24 | this.replicationFactor = replicationFactor;
25 | return this;
26 | }
27 |
28 | public Datacenter networkTopologyStrategy() {
29 | strategy = REPLICATION_STRATEGY_NETWORK_TOPOLOGY;
30 | return new Datacenter(keyspace);
31 | }
32 |
33 | protected StringBuilder buildReplicationStrategy(StringBuilder sb) {
34 | sb.append(" WITH REPLICATION = { 'class' : '");
35 |
36 | if (REPLICATION_STRATEGY_SIMPLE.equals(strategy)) {
37 | sb.append(REPLICATION_STRATEGY_SIMPLE)
38 | .append("', 'replication_factor' : ")
39 | .append(replicationFactor);
40 | } else {
41 | sb.append(REPLICATION_STRATEGY_NETWORK_TOPOLOGY)
42 | .append("'");
43 | for (Map.Entry entry : dcReplicationFactors.entrySet()) {
44 | sb.append(", '")
45 | .append(entry.getKey())
46 | .append("' : ")
47 | .append(entry.getValue());
48 | }
49 | }
50 |
51 | return sb;
52 | }
53 |
54 | public class Datacenter extends BuiltKeyspaceStatement {
55 |
56 | private Datacenter(String keyspace) {
57 | super(keyspace);
58 | }
59 |
60 | public Datacenter dc(String name, int replicationFactor) {
61 | dcReplicationFactors.put(name, replicationFactor);
62 | return this;
63 | }
64 |
65 | /**
66 | * Builds the CQL3 statement
67 | *
68 | * @return a {@link StringBuilder} of the CQL statement
69 | */
70 | @Override
71 | public StringBuilder buildQueryString() {
72 | return KeyspaceBuilderBase.this.buildQueryString();
73 | }
74 | }
75 | }
76 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/promises/WhenCassandraSession.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.promises;
2 |
3 | import com.datastax.driver.core.*;
4 | import com.englishtown.promises.Promise;
5 | import com.englishtown.vertx.cassandra.CassandraSession;
6 |
7 | /**
8 | * When.java wrapper over {@link com.datastax.driver.core.Session}
9 | */
10 | public interface WhenCassandraSession extends AutoCloseable {
11 |
12 | /**
13 | * Executes a cassandra statement asynchronously. Ensures the callback is executed on the correct vert.x context.
14 | *
15 | * @param statement the statement to execute
16 | * @return the promise for the {@link com.datastax.driver.core.ResultSet}
17 | */
18 | Promise executeAsync(Statement statement);
19 |
20 | /**
21 | * Executes a cassandra CQL query asynchronously. Ensures the callback is executed on the correct vert.x context.
22 | *
23 | * @param query the CQL query to execute
24 | * @return the promise for the {@link com.datastax.driver.core.ResultSet}
25 | */
26 | Promise executeAsync(String query);
27 |
28 | /**
29 | * This is a convenience method for {@code executeAsync(new SimpleStatement(query, values))}.
30 | *
31 | * @param query
32 | * @param values
33 | * @return
34 | */
35 | Promise executeAsync(String query, Object... values);
36 |
37 | /**
38 | * Prepares the provided query statement
39 | *
40 | * @param statement the query statement to prepare
41 | * @return the promise for the {@link com.datastax.driver.core.PreparedStatement}
42 | */
43 | Promise prepareAsync(RegularStatement statement);
44 |
45 | /**
46 | * Prepares the provided query
47 | *
48 | * @param query the query to prepare
49 | * @return the promise for the {@link com.datastax.driver.core.PreparedStatement}
50 | */
51 | Promise prepareAsync(String query);
52 |
53 | /**
54 | * Returns cassandra metadata
55 | *
56 | * @return returns the cassandra metadata for the current session
57 | */
58 | Metadata getMetadata();
59 |
60 | /**
61 | * Whether this Session instance has been closed.
62 | *
63 | * @return {@code true} if this Session instance has been closed, {@code false}
64 | * otherwise.
65 | */
66 | boolean isClosed();
67 |
68 | /**
69 | * Returns the {@code Cluster} object this session is part of.
70 | *
71 | * @return the {@code Cluster} object this session is part of.
72 | */
73 | Cluster getCluster();
74 |
75 | /**
76 | * Return the {@link com.englishtown.vertx.cassandra.CassandraSession}
77 | *
78 | * @return
79 | */
80 | CassandraSession getSession();
81 |
82 | /**
83 | * Promise for when the session is ready
84 | *
85 | * @return
86 | */
87 | Promise ready();
88 |
89 | }
90 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/promises/impl/DefaultWhenCassandraSession.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.promises.impl;
2 |
3 | import com.datastax.driver.core.*;
4 | import com.englishtown.promises.Deferred;
5 | import com.englishtown.promises.Promise;
6 | import com.englishtown.promises.When;
7 | import com.englishtown.vertx.cassandra.CassandraSession;
8 | import com.englishtown.vertx.cassandra.FutureUtils;
9 | import com.englishtown.vertx.cassandra.promises.WhenCassandraSession;
10 | import com.google.common.util.concurrent.FutureCallback;
11 | import com.google.common.util.concurrent.ListenableFuture;
12 | import io.vertx.core.Vertx;
13 |
14 | import javax.inject.Inject;
15 |
16 | /**
17 | * Default implementation of {@link com.englishtown.vertx.cassandra.promises.WhenCassandraSession}
18 | */
19 | public class DefaultWhenCassandraSession implements WhenCassandraSession {
20 |
21 | private final CassandraSession session;
22 | private final When when;
23 | private final Vertx vertx;
24 |
25 | @Inject
26 | public DefaultWhenCassandraSession(CassandraSession session, When when, Vertx vertx) {
27 | this.session = session;
28 | this.when = when;
29 | this.vertx = vertx;
30 | }
31 |
32 | /**
33 | * Executes a cassandra statement asynchronously. Ensures the callback is executed on the correct vert.x context.
34 | *
35 | * @param statement the statement to execute
36 | * @return the promise for the {@link com.datastax.driver.core.ResultSet}
37 | */
38 | @Override
39 |
40 | public Promise executeAsync(Statement statement) {
41 | return convertFuture(session.executeAsync(statement));
42 | }
43 |
44 | /**
45 | * Executes a cassandra CQL query asynchronously. Ensures the callback is executed on the correct vert.x context.
46 | *
47 | * @param query the CQL query to execute
48 | * @return the promise for the {@link com.datastax.driver.core.ResultSet}
49 | */
50 | @Override
51 | public Promise executeAsync(String query) {
52 | return convertFuture(session.executeAsync(query));
53 | }
54 |
55 | /**
56 | * This is a convenience method for {@code executeAsync(new SimpleStatement(query, values))}.
57 | *
58 | * @param query
59 | * @param values
60 | * @return
61 | */
62 | @Override
63 | public Promise executeAsync(String query, Object... values) {
64 | return convertFuture(session.executeAsync(query, values));
65 | }
66 |
67 | /**
68 | * Prepares the provided query statement
69 | *
70 | * @param statement the query statement to prepare
71 | * @return the promise for the {@link com.datastax.driver.core.PreparedStatement}
72 | */
73 | @Override
74 | public Promise prepareAsync(RegularStatement statement) {
75 | return convertFuture(session.prepareAsync(statement));
76 | }
77 |
78 | /**
79 | * Prepares the provided query
80 | *
81 | * @param query the query to prepare
82 | * @return the promise for the {@link com.datastax.driver.core.PreparedStatement}
83 | */
84 | @Override
85 | public Promise prepareAsync(String query) {
86 | return convertFuture(session.prepareAsync(query));
87 | }
88 |
89 | /**
90 | * Returns cassandra metadata
91 | *
92 | * @return returns the cassandra metadata for the current session
93 | */
94 | @Override
95 | public Metadata getMetadata() {
96 | return session.getMetadata();
97 | }
98 |
99 | /**
100 | * Whether this Session instance has been closed.
101 | *
102 | * @return {@code true} if this Session instance has been closed, {@code false}
103 | * otherwise.
104 | */
105 | @Override
106 | public boolean isClosed() {
107 | return session.isClosed();
108 | }
109 |
110 | /**
111 | * Returns the {@code Cluster} object this session is part of.
112 | *
113 | * @return the {@code Cluster} object this session is part of.
114 | */
115 | @Override
116 | public Cluster getCluster() {
117 | return session.getCluster();
118 | }
119 |
120 | /**
121 | * Return the {@link com.englishtown.vertx.cassandra.CassandraSession}
122 | *
123 | * @return
124 | */
125 | @Override
126 | public CassandraSession getSession() {
127 | return session;
128 | }
129 |
130 | /**
131 | * Promise for when the session is ready
132 | *
133 | * @return
134 | */
135 | @Override
136 | public Promise ready() {
137 | Deferred d = when.defer();
138 |
139 | session.onReady(result -> {
140 | if (result.succeeded()) {
141 | d.resolve((Void) null);
142 | } else {
143 | d.reject(result.cause());
144 | }
145 | });
146 |
147 | return d.getPromise();
148 | }
149 |
150 | /**
151 | * {@inheritDoc}
152 | */
153 | @Override
154 | public void close() throws Exception {
155 | session.close();
156 | }
157 |
158 | private Promise convertFuture(ListenableFuture future) {
159 |
160 | Deferred d = when.defer();
161 |
162 | FutureCallback callback = new FutureCallback() {
163 | @Override
164 | public void onSuccess(T result) {
165 | d.resolve(result);
166 | }
167 |
168 | @Override
169 | public void onFailure(Throwable t) {
170 | d.reject(t);
171 | }
172 | };
173 |
174 | FutureUtils.addCallback(future, callback, vertx);
175 | return d.getPromise();
176 |
177 | }
178 |
179 | }
180 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/tablebuilder/AlterTable.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.tablebuilder;
2 |
3 | /**
4 | * ALTER TABLE CQL3 statement builder
5 | */
6 | public class AlterTable extends BuiltTableStatement {
7 |
8 | private Column alterColumn;
9 | private Column addColumn;
10 | private Column dropColumn;
11 | private Column renameColumnFrom;
12 | private Column renameColumnTo;
13 |
14 | AlterTable(String keyspace, String table) {
15 | super(keyspace, table);
16 | }
17 |
18 | public AlterTable alterColumn(String column, String type) {
19 | alterColumn = new Column(column, type, false);
20 | return this;
21 | }
22 |
23 | public AlterTable addColumn(String column, String type) {
24 | addColumn = new Column(column, type, false);
25 | return this;
26 | }
27 |
28 | public AlterTable dropColumn(String column) {
29 | dropColumn = new Column(column, null, false);
30 | return this;
31 | }
32 |
33 | public AlterTable renameColumn(String columnFrom, String columnTo) {
34 | renameColumnFrom = new Column(columnFrom, null, false);
35 | renameColumnTo = new Column(columnTo, null, false);
36 | return this;
37 | }
38 |
39 | /**
40 | * {@inheritDoc}
41 | */
42 | @Override
43 | public StringBuilder buildQueryString() {
44 | StringBuilder sb = new StringBuilder();
45 |
46 | sb.append("ALTER TABLE ");
47 | if (keyspace != null) {
48 | sb.append(keyspace).append(".");
49 | }
50 | sb.append(table).append(" ");
51 |
52 | if (alterColumn != null) {
53 | sb.append("ALTER ")
54 | .append(alterColumn.getName())
55 | .append(" TYPE ")
56 | .append(alterColumn.getType());
57 | } else if (addColumn != null) {
58 | sb.append("ADD ")
59 | .append(addColumn.getName())
60 | .append(" ")
61 | .append(addColumn.getType());
62 | } else if (dropColumn != null) {
63 | sb.append("DROP ")
64 | .append(dropColumn.getName());
65 | } else if (renameColumnFrom != null && renameColumnTo != null) {
66 | sb.append("RENAME ")
67 | .append(renameColumnFrom.getName())
68 | .append(" TO ")
69 | .append(renameColumnTo.getName());
70 | }
71 |
72 | return sb;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/tablebuilder/BuiltTableStatement.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.tablebuilder;
2 |
3 | import com.datastax.driver.core.CodecRegistry;
4 | import com.datastax.driver.core.ProtocolVersion;
5 | import com.datastax.driver.core.RegularStatement;
6 |
7 | import java.nio.ByteBuffer;
8 | import java.util.Map;
9 |
10 | /**
11 | * Builds a CQL3 statement to manipulate tables
12 | */
13 | public abstract class BuiltTableStatement extends RegularStatement {
14 |
15 | protected String keyspace;
16 | protected String table;
17 |
18 | protected BuiltTableStatement(String keyspace, String table) {
19 | this.keyspace = keyspace;
20 | this.table = table;
21 | }
22 |
23 | /**
24 | * Builds the CQL3 statement
25 | *
26 | * @return a {@link java.lang.StringBuilder} of the CQL statement
27 | */
28 | public abstract StringBuilder buildQueryString();
29 |
30 | /**
31 | * {@inheritDoc}
32 | */
33 | @Override
34 | public String getQueryString() {
35 | return buildQueryString().toString();
36 | }
37 |
38 | @Override
39 | public String getQueryString(CodecRegistry codecRegistry) {
40 | return getQueryString();
41 | }
42 |
43 | /**
44 | * {@inheritDoc}
45 | */
46 | @Override
47 | public ByteBuffer[] getValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry) {
48 | return null;
49 | }
50 |
51 | /**
52 | * {@inheritDoc}
53 | */
54 | @Override
55 | public boolean hasValues(CodecRegistry codecRegistry) {
56 | return false;
57 | }
58 |
59 | /**
60 | * {@inheritDoc}
61 | */
62 | @Override
63 | public ByteBuffer getRoutingKey(ProtocolVersion protocolVersion, CodecRegistry codecRegistry) {
64 | return null;
65 | }
66 |
67 | /**
68 | * {@inheritDoc}
69 | */
70 | @Override
71 | public String getKeyspace() {
72 | return keyspace;
73 | }
74 |
75 | /**
76 | * Returns the table name
77 | *
78 | * @return the table name
79 | */
80 | public String getTable() {
81 | return table;
82 | }
83 |
84 | /**
85 | * {@inheritDoc}
86 | */
87 | @Override
88 | public Map getNamedValues(ProtocolVersion protocolVersion, CodecRegistry codecRegistry) {
89 | return null;
90 | }
91 |
92 | /**
93 | * {@inheritDoc}
94 | */
95 | @Override
96 | public boolean usesNamedValues() {
97 | return false;
98 | }
99 |
100 | /**
101 | * A CQL3 column
102 | */
103 | public static class Column {
104 |
105 | protected Column(String name, String type, boolean isStatic) {
106 | this.name = name;
107 | this.type = type;
108 | this.isStatic = isStatic;
109 | }
110 |
111 | private String name;
112 | private String type;
113 | private boolean isStatic;
114 |
115 | public String getName() {
116 | return name;
117 | }
118 |
119 | public String getType() {
120 | return type;
121 | }
122 |
123 | public boolean getIsStatic() {
124 | return isStatic;
125 | }
126 |
127 | }
128 |
129 | }
130 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/tablebuilder/CreateTable.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.tablebuilder;
2 |
3 | import java.util.*;
4 |
5 | /**
6 | * CREATE TABLE CQL3 statement builder
7 | */
8 | public class CreateTable extends BuiltTableStatement {
9 |
10 |
11 | private Map columns = new TreeMap<>();
12 | private boolean ifNotExists = false;
13 | private Set primaryKeys = new LinkedHashSet<>();
14 | private Set partitioningKeys = new LinkedHashSet<>();
15 |
16 | CreateTable(String keyspace, String table) {
17 | super(keyspace, table);
18 | }
19 |
20 | /**
21 | * Returns a collection of the columns to be created
22 | *
23 | * @return collection of columns to create
24 | */
25 | public Collection getColumns() {
26 | return columns.values();
27 | }
28 |
29 | /**
30 | * Adds the "IF NOT EXISTS" cql clause
31 | *
32 | * @return the current {@link com.englishtown.vertx.cassandra.tablebuilder.CreateTable}
33 | */
34 | public CreateTable ifNotExists() {
35 | ifNotExists = true;
36 | return this;
37 | }
38 |
39 | /**
40 | * Adds a column
41 | *
42 | * @param name the column name
43 | * @param type the column CQL3 type
44 | * @return the current {@link com.englishtown.vertx.cassandra.tablebuilder.BuiltTableStatement}
45 | */
46 | public CreateTable column(String name, String type) {
47 | return addColumn(new Column(name, type, false));
48 | }
49 |
50 | /**
51 | * Adds a column
52 | *
53 | * @param name the column name
54 | * @param type the column CQL3 type
55 | * @return the current {@link com.englishtown.vertx.cassandra.tablebuilder.BuiltTableStatement}
56 | */
57 | public CreateTable staticColumn(String name, String type) {
58 | return addColumn(new Column(name, type, true));
59 | }
60 |
61 | private CreateTable addColumn(Column column) {
62 | columns.put(column.getName(), column);
63 | return this;
64 | }
65 |
66 | /**
67 | * Adds multiple columns
68 | *
69 | * @param names the column names
70 | * @param types the column CQL3 types
71 | * @return the current {@link com.englishtown.vertx.cassandra.tablebuilder.BuiltTableStatement}
72 | */
73 | public CreateTable columns(String[] names, String[] types) {
74 | if (names.length != types.length) {
75 | throw new IllegalArgumentException(String.format("Got %d names but %d types", names.length, types.length));
76 | }
77 | for (int i = 0; i < names.length; i++) {
78 | column(names[i], types[i]);
79 | }
80 | return this;
81 | }
82 |
83 | /**
84 | * Sets one or more primary key columns
85 | *
86 | * @param column column name
87 | * @return the current {@link com.englishtown.vertx.cassandra.tablebuilder.CreateTable}
88 | */
89 | public CreateTable primaryKeys(String... column) {
90 | Collections.addAll(primaryKeys, column);
91 | return this;
92 | }
93 |
94 | /**
95 | * Sets a primary key
96 | *
97 | * @param column column name
98 | * @return the current {@link com.englishtown.vertx.cassandra.tablebuilder.CreateTable}
99 | */
100 | public CreateTable primaryKey(String column) {
101 | primaryKeys.add(column);
102 | return this;
103 | }
104 |
105 | /**
106 | * Sets a primary key and type. This allows you to create a table with a composite partition key
107 | *
108 | * @param column column name
109 | * @param type partitioning or clustering
110 | * @return the current {@link com.englishtown.vertx.cassandra.tablebuilder.CreateTable}
111 | */
112 | public CreateTable primaryKey(String column, PrimaryKeyType type) {
113 | switch (type) {
114 | case PARTITIONING:
115 | primaryKeys.remove(column);
116 | partitioningKeys.add(column);
117 | break;
118 | default:
119 | primaryKeys.add(column);
120 | break;
121 | }
122 | return this;
123 | }
124 |
125 | /**
126 | * {@inheritDoc}
127 | */
128 | public StringBuilder buildQueryString() {
129 | StringBuilder sb = new StringBuilder();
130 |
131 | sb.append("CREATE TABLE ");
132 | if (ifNotExists) {
133 | sb.append("IF NOT EXISTS ");
134 | }
135 | if (keyspace != null) {
136 | sb.append(keyspace).append(".");
137 | }
138 | sb.append(table).append(" (");
139 |
140 | String delimiter = "";
141 |
142 | // Add columns
143 | for (Column column : columns.values()) {
144 | sb.append(delimiter).append(column.getName()).append(" ").append(column.getType());
145 | if (column.getIsStatic()) {
146 | sb.append(" STATIC");
147 | }
148 | delimiter = ", ";
149 | }
150 |
151 | // Add primary keys
152 | sb.append(delimiter).append("PRIMARY KEY(");
153 | delimiter = "";
154 | if (!partitioningKeys.isEmpty()) {
155 | sb.append("(");
156 | for (String column : partitioningKeys) {
157 | sb.append(delimiter).append(column);
158 | delimiter = ", ";
159 | }
160 | sb.append(")");
161 | }
162 | for (String column : primaryKeys) {
163 | sb.append(delimiter).append(column);
164 | delimiter = ", ";
165 | }
166 | sb.append(")");
167 |
168 | sb.append(")");
169 |
170 | return sb;
171 | }
172 |
173 | /**
174 | * {@inheritDoc}
175 | */
176 | @Override
177 | public String toString() {
178 | return getQueryString();
179 | }
180 |
181 | }
182 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/tablebuilder/DropTable.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.tablebuilder;
2 |
3 | /**
4 | * DROP TABLE CQL3 statement builder
5 | */
6 | public class DropTable extends BuiltTableStatement {
7 |
8 | private boolean ifExists = false;
9 |
10 | DropTable(String keyspace, String table) {
11 | super(keyspace, table);
12 | }
13 |
14 | public DropTable ifExists() {
15 | ifExists = true;
16 | return this;
17 | }
18 |
19 | /**
20 | * {@inheritDoc}
21 | */
22 | @Override
23 | public StringBuilder buildQueryString() {
24 | StringBuilder sb = new StringBuilder();
25 |
26 | sb.append("DROP TABLE ");
27 | if (ifExists) {
28 | sb.append("IF EXISTS ");
29 | }
30 | if (keyspace != null) {
31 | sb.append(keyspace).append(".");
32 | }
33 | sb.append(table);
34 |
35 | return sb;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/tablebuilder/PrimaryKeyType.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.tablebuilder;
2 |
3 | /**
4 | * CQL3 Primary Key types
5 | */
6 | public enum PrimaryKeyType {
7 | /**
8 | * A partitioning primary key
9 | * Useful for composite partitioning primary keys
10 | */
11 | PARTITIONING,
12 | /**
13 | * A clustering primary key used in compound primary keys
14 | */
15 | CLUSTERING
16 | }
17 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/tablebuilder/TableBuilder.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.tablebuilder;
2 |
3 | import com.datastax.driver.core.AbstractTableMetadata;
4 | import com.datastax.driver.core.ColumnMetadata;
5 | import com.datastax.driver.core.TableMetadata;
6 |
7 | import java.util.ArrayList;
8 | import java.util.List;
9 |
10 | /**
11 | * Static methods to build a CQL3 table statement
12 | */
13 | public final class TableBuilder {
14 |
15 | private TableBuilder() {
16 | }
17 |
18 | /**
19 | * Returns a {@link com.englishtown.vertx.cassandra.tablebuilder.CreateTable} builder
20 | *
21 | * @param keyspace the keyspace for the table to create
22 | * @param table the table name
23 | * @return the create table builder
24 | */
25 | public static CreateTable create(String keyspace, String table) {
26 | return new CreateTable(keyspace, table);
27 | }
28 |
29 | /**
30 | * Returns a {@link com.englishtown.vertx.cassandra.tablebuilder.AlterTable} builder
31 | *
32 | * @param keyspace the keyspace for the table to create
33 | * @param table the table name
34 | * @return the create table builder
35 | */
36 | public static AlterTable alter(String keyspace, String table) {
37 | return new AlterTable(keyspace, table);
38 | }
39 |
40 | /**
41 | * Returns a {@link com.datastax.driver.core.BatchStatement} with all the alter statements necessary to modify an existing table.
42 | *
43 | * Note: Columns will only be added or modified, not dropped.
44 | *
45 | * @param existing the existing table to be modified
46 | * @param desired the desired end result
47 | * @return a set of statements to modify an existing table
48 | */
49 | public static List alter(AbstractTableMetadata existing, CreateTable desired) {
50 | List results = new ArrayList<>();
51 |
52 | for (BuiltTableStatement.Column column : desired.getColumns()) {
53 | ColumnMetadata columnMetadata = existing.getColumn(column.getName());
54 | if (columnMetadata == null) {
55 | results.add(alter(desired.getKeyspace(), desired.getTable()).addColumn(column.getName(), column.getType()));
56 | } else if (!columnMetadata.getType().toString().equalsIgnoreCase(column.getType())) {
57 | if (columnMetadata.isStatic()) {
58 | throw new IllegalArgumentException("A static column cannot have its type modified");
59 | }
60 | results.add(alter(desired.getKeyspace(), desired.getTable()).alterColumn(column.getName(), column.getType()));
61 | }
62 | }
63 |
64 | return results;
65 | }
66 |
67 | /**
68 | * Returns a {@link com.englishtown.vertx.cassandra.tablebuilder.DropTable} statement
69 | *
70 | * @param keyspace the keyspace for the table to create
71 | * @param table the table name
72 | * @return the drop table builder
73 | */
74 | public static DropTable drop(String keyspace, String table) {
75 | return new DropTable(keyspace, table);
76 | }
77 |
78 | }
79 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/main/java/com/englishtown/vertx/cassandra/zookeeper/ZooKeeperCassandraConfigurator.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.zookeeper;
2 |
3 | import com.englishtown.promises.Promise;
4 | import com.englishtown.promises.When;
5 | import com.englishtown.vertx.cassandra.impl.EnvironmentCassandraConfigurator;
6 | import com.englishtown.vertx.curator.CuratorClient;
7 | import com.englishtown.vertx.curator.promises.WhenConfiguratorHelper;
8 | import io.vertx.core.AsyncResult;
9 | import io.vertx.core.Future;
10 | import io.vertx.core.Handler;
11 | import io.vertx.core.Vertx;
12 | import io.vertx.core.json.JsonArray;
13 | import io.vertx.core.json.JsonObject;
14 | import org.apache.curator.utils.ZKPaths;
15 |
16 | import javax.inject.Inject;
17 | import java.util.ArrayList;
18 | import java.util.List;
19 |
20 | /**
21 | * ZooKeeper implementation of {@link com.englishtown.vertx.cassandra.CassandraConfigurator}
22 | */
23 | public class ZooKeeperCassandraConfigurator extends EnvironmentCassandraConfigurator {
24 |
25 | private final WhenConfiguratorHelper helper;
26 | private final When when;
27 | private AsyncResult initResult;
28 | private final List>> onReadyCallbacks = new ArrayList<>();
29 | protected String pathPrefix = "cassandra";
30 |
31 | @Inject
32 | public ZooKeeperCassandraConfigurator(CuratorClient client, WhenConfiguratorHelper helper, When when, Vertx vertx, EnvVarDelegate envVarDelegate) {
33 | super(vertx, envVarDelegate);
34 | this.helper = helper;
35 | this.when = when;
36 |
37 | client.onReady(result -> {
38 | if (result.failed()) {
39 | runOnReadyCallbacks(result);
40 | return;
41 | }
42 | initZooKeeper();
43 | });
44 | }
45 |
46 | private void initZooKeeper() {
47 |
48 | List> promises = new ArrayList<>();
49 |
50 | if (DEFAULT_SEEDS.equals(seeds)) {
51 | promises.add(helper.getConfigElement(ZKPaths.makePath(getPathPrefix(), "seeds")).then(
52 | value -> {
53 | JsonArray array = value.asJsonArray();
54 | if (array != null) {
55 | initSeeds(array);
56 | }
57 | return null;
58 | }));
59 | }
60 |
61 | if (loadBalancingPolicy == null) {
62 | promises.add(helper.getConfigElement(ZKPaths.makePath(getPathPrefix(), "policies/load_balancing")).then(
63 | value -> {
64 | JsonObject json = value.asJsonObject();
65 | if (json != null) {
66 | initLoadBalancingPolicy(json);
67 | }
68 | return null;
69 | }));
70 | }
71 |
72 | if (reconnectionPolicy == null) {
73 | promises.add(helper.getConfigElement(ZKPaths.makePath(getPathPrefix(), "policies/reconnection")).then(
74 | value -> {
75 | JsonObject json = value.asJsonObject();
76 | if (json != null) {
77 | initLoadBalancingPolicy(json);
78 | }
79 | return null;
80 | }));
81 | }
82 |
83 | if (poolingOptions == null) {
84 | promises.add(helper.getConfigElement(ZKPaths.makePath(getPathPrefix(), "pooling")).then(
85 | value -> {
86 | JsonObject json = value.asJsonObject();
87 | if (json != null) {
88 | initPoolingOptions(json);
89 | }
90 | return null;
91 | }));
92 | }
93 |
94 | if (socketOptions == null) {
95 | promises.add(helper.getConfigElement(ZKPaths.makePath(getPathPrefix(), "socket")).then(
96 | value -> {
97 | JsonObject json = value.asJsonObject();
98 | if (json != null) {
99 | initSocketOptions(json);
100 | }
101 | return null;
102 | }));
103 | }
104 |
105 | if (queryOptions == null) {
106 | promises.add(helper.getConfigElement(ZKPaths.makePath(getPathPrefix(), "query")).then(
107 | value -> {
108 | JsonObject json = value.asJsonObject();
109 | if (json != null) {
110 | initQueryOptions(json);
111 | }
112 | return null;
113 | }));
114 | }
115 |
116 | if (metricsOptions == null) {
117 | promises.add(helper.getConfigElement(ZKPaths.makePath(getPathPrefix(), "metrics")).then(
118 | value -> {
119 | JsonObject json = value.asJsonObject();
120 | if (json != null) {
121 | initMetricsOptions(json);
122 | }
123 | return null;
124 | }));
125 | }
126 |
127 | if (authProvider == null) {
128 | promises.add(helper.getConfigElement(ZKPaths.makePath(getPathPrefix(), "auth")).then(
129 | value -> {
130 | JsonObject json = value.asJsonObject();
131 | if (json != null) {
132 | initAuthProvider(json);
133 | }
134 | return null;
135 | }));
136 | }
137 |
138 | when.all(promises)
139 | .then(aVoid -> {
140 | runOnReadyCallbacks(Future.succeededFuture(null));
141 | return null;
142 | })
143 | .otherwise(t -> {
144 | runOnReadyCallbacks(Future.failedFuture(t));
145 | return null;
146 | });
147 | }
148 |
149 | private void runOnReadyCallbacks(AsyncResult result) {
150 | initResult = result;
151 | onReadyCallbacks.forEach(callback -> callback.handle(result));
152 | onReadyCallbacks.clear();
153 | }
154 |
155 | @Override
156 | public void onReady(Handler> callback) {
157 | if (initResult != null) {
158 | callback.handle(initResult);
159 | } else {
160 | onReadyCallbacks.add(callback);
161 | }
162 | }
163 |
164 | protected String getPathPrefix() {
165 | return pathPrefix;
166 | }
167 |
168 | }
169 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/impl/DefaultCassandraSessionTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.impl;
2 |
3 | import com.datastax.driver.core.*;
4 | import com.datastax.driver.core.policies.LoadBalancingPolicy;
5 | import com.datastax.driver.core.querybuilder.QueryBuilder;
6 | import com.englishtown.vertx.cassandra.CassandraConfigurator;
7 | import com.google.common.util.concurrent.FutureCallback;
8 | import com.google.common.util.concurrent.ListenableFuture;
9 | import com.google.common.util.concurrent.SettableFuture;
10 | import io.vertx.core.*;
11 | import org.junit.Before;
12 | import org.junit.Test;
13 | import org.junit.runner.RunWith;
14 | import org.mockito.ArgumentCaptor;
15 | import org.mockito.Captor;
16 | import org.mockito.Mock;
17 | import org.mockito.runners.MockitoJUnitRunner;
18 |
19 | import java.util.ArrayList;
20 | import java.util.Collection;
21 | import java.util.Iterator;
22 | import java.util.List;
23 | import java.util.concurrent.CompletableFuture;
24 | import java.util.concurrent.Executor;
25 | import java.util.function.BiConsumer;
26 | import java.util.function.Consumer;
27 |
28 | import static org.junit.Assert.assertEquals;
29 | import static org.junit.Assert.fail;
30 | import static org.mockito.Matchers.anyString;
31 | import static org.mockito.Mockito.*;
32 |
33 | /**
34 | * Unit tests for {@link DefaultCassandraSession}
35 | */
36 | @RunWith(MockitoJUnitRunner.class)
37 | public class DefaultCassandraSessionTest {
38 |
39 | DefaultCassandraSession cassandraSession;
40 | List seeds = new ArrayList<>();
41 | Configuration configuration = Configuration.builder().build();
42 |
43 | @Mock
44 | Vertx vertx;
45 | @Mock
46 | Context context;
47 | @Mock
48 | CassandraConfigurator configurator;
49 | @Mock
50 | Cluster.Builder clusterBuilder;
51 | @Mock
52 | Cluster cluster;
53 | @Mock
54 | Session session;
55 | @Mock
56 | Metadata metadata;
57 | @Mock
58 | FutureCallback callback;
59 | @Mock
60 | ListenableFuture preparedStatementFuture;
61 | @Mock
62 | FutureCallback preparedStatementCallback;
63 | @Mock
64 | CloseFuture closeFuture;
65 | @Captor
66 | ArgumentCaptor statementCaptor;
67 | @Captor
68 | ArgumentCaptor queryCaptor;
69 | @Captor
70 | ArgumentCaptor runnableCaptor;
71 | @Captor
72 | ArgumentCaptor> handlerCaptor;
73 | @Captor
74 | ArgumentCaptor>> onReadyCaptor;
75 | @Captor
76 | ArgumentCaptor executorCaptor;
77 |
78 | private BiConsumer> onReadyFail = (cassandraSession, future) -> {
79 | cassandraSession.onReady(result -> {
80 | if (result.succeeded()) {
81 | future.completeExceptionally(new RuntimeException("Should not succeed"));
82 | } else {
83 | future.complete(null);
84 | }
85 | });
86 | };
87 |
88 | public static class TestLoadBalancingPolicy implements LoadBalancingPolicy {
89 | @Override
90 | public void init(Cluster cluster, Collection hosts) {
91 | }
92 |
93 | @Override
94 | public HostDistance distance(Host host) {
95 | return null;
96 | }
97 |
98 | @Override
99 | public Iterator newQueryPlan(String loggedKeyspace, Statement statement) {
100 | return null;
101 | }
102 |
103 | @Override
104 | public void onAdd(Host host) {
105 | }
106 |
107 | @Override
108 | public void onUp(Host host) {
109 | }
110 |
111 | @Override
112 | public void onDown(Host host) {
113 | }
114 |
115 | @Override
116 | public void onRemove(Host host) {
117 | }
118 |
119 | @Override
120 | public void close() {
121 |
122 | }
123 | }
124 |
125 | @Before
126 | public void setUp() {
127 |
128 | SettableFuture sessionFuture = SettableFuture.create();
129 |
130 | when(vertx.getOrCreateContext()).thenReturn(context);
131 | doAnswer(invocation -> {
132 | Handler handler = (Handler) invocation.getArguments()[0];
133 | handler.handle(null);
134 | return null;
135 | }).when(context).runOnContext(any());
136 |
137 | when(clusterBuilder.build()).thenReturn(cluster);
138 | when(cluster.getConfiguration()).thenReturn(configuration);
139 | when(cluster.connectAsync()).thenReturn(sessionFuture);
140 | when(cluster.getMetadata()).thenReturn(metadata);
141 | when(cluster.closeAsync()).thenReturn(closeFuture);
142 | when(closeFuture.force()).thenReturn(closeFuture);
143 |
144 | when(configurator.getSeeds()).thenReturn(seeds);
145 | seeds.add("127.0.0.1");
146 |
147 | when(session.getCluster()).thenReturn(cluster);
148 | when(session.prepareAsync(any(RegularStatement.class))).thenReturn(preparedStatementFuture);
149 | when(session.prepareAsync(anyString())).thenReturn(preparedStatementFuture);
150 |
151 | cassandraSession = new DefaultCassandraSession(clusterBuilder, configurator, vertx);
152 |
153 | verify(configurator).onReady(onReadyCaptor.capture());
154 | onReadyCaptor.getValue().handle(Future.succeededFuture());
155 |
156 | sessionFuture.set(session);
157 |
158 | }
159 |
160 | @Test
161 | public void testInit() throws Exception {
162 |
163 | seeds.clear();
164 | seeds.add("127.0.0.1");
165 | seeds.add("127.0.0.2");
166 | seeds.add("127.0.0.3");
167 |
168 | LoadBalancingPolicy lbPolicy = mock(LoadBalancingPolicy.class);
169 | when(configurator.getLoadBalancingPolicy()).thenReturn(lbPolicy);
170 | PoolingOptions poolingOptions = mock(PoolingOptions.class);
171 | when(configurator.getPoolingOptions()).thenReturn(poolingOptions);
172 | SocketOptions socketOptions = mock(SocketOptions.class);
173 | when(configurator.getSocketOptions()).thenReturn(socketOptions);
174 | QueryOptions queryOptions = mock(QueryOptions.class);
175 | when(configurator.getQueryOptions()).thenReturn(queryOptions);
176 | MetricsOptions metricsOptions = mock(MetricsOptions.class);
177 | when(configurator.getMetricsOptions()).thenReturn(metricsOptions);
178 |
179 | cassandraSession.init(configurator);
180 | verify(clusterBuilder, times(4)).addContactPoint(anyString());
181 | verify(clusterBuilder).withLoadBalancingPolicy(eq(lbPolicy));
182 | verify(clusterBuilder).withPoolingOptions(eq(poolingOptions));
183 | verify(clusterBuilder, times(2)).build();
184 | verify(cluster, times(2)).connectAsync();
185 |
186 | verify(cluster, times(0)).getMetadata();
187 | cassandraSession.getMetadata();
188 | verify(cluster, times(1)).getMetadata();
189 |
190 | verify(cluster, times(0)).isClosed();
191 | verify(session, times(0)).isClosed();
192 | cassandraSession.isClosed();
193 | verify(cluster, times(0)).isClosed();
194 | verify(session, times(1)).isClosed();
195 |
196 | assertEquals(cluster, cassandraSession.getCluster());
197 |
198 | seeds.clear();
199 | try {
200 | cassandraSession.init(configurator);
201 | fail();
202 | } catch (Throwable t) {
203 | // Expected
204 | }
205 |
206 | }
207 |
208 | @Test
209 | public void testCtorInitFail() throws Exception {
210 |
211 | seeds.clear();
212 | reset(configurator);
213 |
214 | DefaultCassandraSession cassandraSession = new DefaultCassandraSession(clusterBuilder, configurator, vertx);
215 |
216 | CompletableFuture future = new CompletableFuture<>();
217 | onReadyFail.accept(cassandraSession, future);
218 |
219 | verify(configurator).onReady(onReadyCaptor.capture());
220 | onReadyCaptor.getValue().handle(Future.succeededFuture());
221 | future.get();
222 |
223 | future = new CompletableFuture<>();
224 | onReadyFail.accept(cassandraSession, future);
225 | future.get();
226 |
227 | }
228 |
229 | @Test
230 | public void testCtorReadyFail() throws Exception {
231 |
232 | reset(configurator);
233 |
234 | DefaultCassandraSession cassandraSession = new DefaultCassandraSession(clusterBuilder, configurator, vertx);
235 |
236 | CompletableFuture future = new CompletableFuture<>();
237 | onReadyFail.accept(cassandraSession, future);
238 |
239 | verify(configurator).onReady(onReadyCaptor.capture());
240 | onReadyCaptor.getValue().handle(Future.failedFuture("Test fail"));
241 | future.get();
242 |
243 | future = new CompletableFuture<>();
244 | onReadyFail.accept(cassandraSession, future);
245 | future.get();
246 |
247 | }
248 |
249 | @Test
250 | public void testExecuteAsync() throws Exception {
251 |
252 | Statement statement = mock(Statement.class);
253 | ResultSetFuture future = mock(ResultSetFuture.class);
254 | when(session.executeAsync(any(Statement.class))).thenReturn(future);
255 |
256 | cassandraSession.executeAsync(statement, callback);
257 | verify(session).executeAsync(eq(statement));
258 | verify(future).addListener(runnableCaptor.capture(), executorCaptor.capture());
259 |
260 | ResultSet resultSet = mock(ResultSet.class);
261 | RuntimeException e = new RuntimeException("Unit test exception");
262 | when(future.get()).thenReturn(resultSet).thenThrow(e);
263 |
264 | executorCaptor.getValue().execute(runnableCaptor.getValue());
265 | verify(context, times(2)).runOnContext(handlerCaptor.capture());
266 | handlerCaptor.getValue().handle(null);
267 | verify(callback).onSuccess(eq(resultSet));
268 |
269 | executorCaptor.getValue().execute(runnableCaptor.getValue());
270 | verify(context, times(3)).runOnContext(handlerCaptor.capture());
271 | handlerCaptor.getValue().handle(null);
272 | verify(callback, times(3)).onFailure(eq(e));
273 |
274 | }
275 |
276 | @Test
277 | public void testExecuteAsync_Query() throws Exception {
278 |
279 | String query = "SELECT * FROM table";
280 | ResultSetFuture future = mock(ResultSetFuture.class);
281 | when(session.executeAsync(anyString())).thenReturn(future);
282 |
283 | cassandraSession.executeAsync(query, callback);
284 | verify(session).executeAsync(queryCaptor.capture());
285 | assertEquals(query, queryCaptor.getValue());
286 | verify(future).addListener(any(Runnable.class), any(Executor.class));
287 |
288 | }
289 |
290 | @Test
291 | public void testExecute() throws Exception {
292 |
293 | String query = "SELECT * FROM table;";
294 |
295 | cassandraSession.execute(query);
296 | verify(session).execute(queryCaptor.capture());
297 | assertEquals(query, queryCaptor.getValue());
298 |
299 | }
300 |
301 | @Test
302 | public void testPrepareAsync_Statement() throws Exception {
303 | RegularStatement statement = QueryBuilder.select()
304 | .from("ks", "table")
305 | .where(QueryBuilder.eq("id", QueryBuilder.bindMarker()));
306 |
307 | cassandraSession.prepareAsync(statement, preparedStatementCallback);
308 | verify(session).prepareAsync(eq(statement));
309 | verify(preparedStatementFuture).addListener(any(Runnable.class), any(Executor.class));
310 | }
311 |
312 | @Test
313 | public void testPrepareAsync_Query() throws Exception {
314 | String query = "SELECT * FROM ks.table where id = ?";
315 | cassandraSession.prepareAsync(query, preparedStatementCallback);
316 | verify(session).prepareAsync(eq(query));
317 | verify(preparedStatementFuture).addListener(any(Runnable.class), any(Executor.class));
318 | }
319 |
320 | @Test
321 | public void testPrepare_Statement() throws Exception {
322 | RegularStatement statement = QueryBuilder.select()
323 | .from("ks", "table")
324 | .where(QueryBuilder.eq("id", QueryBuilder.bindMarker()));
325 |
326 | cassandraSession.prepare(statement);
327 | verify(session).prepare(eq(statement));
328 | }
329 |
330 | @Test
331 | public void testPrepare_Query() throws Exception {
332 | String query = "SELECT * FROM ks.table where id = ?";
333 | cassandraSession.prepare(query);
334 | verify(session).prepare(eq(query));
335 | }
336 |
337 | @Test
338 | public void testGetMetadata() throws Exception {
339 |
340 | assertEquals(metadata, cassandraSession.getMetadata());
341 |
342 | }
343 |
344 | @Test
345 | public void testClose() throws Exception {
346 | cassandraSession.close();
347 | verify(cluster).closeAsync();
348 | verify(closeFuture).force();
349 | }
350 | }
351 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/impl/EnvironmentCassandraConfiguratorTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.impl;
2 |
3 | import com.datastax.driver.core.AuthProvider;
4 | import com.datastax.driver.core.PlainTextAuthProvider;
5 | import com.datastax.driver.core.policies.DCAwareRoundRobinPolicy;
6 | import com.datastax.driver.core.policies.LoadBalancingPolicy;
7 | import io.vertx.core.Context;
8 | import io.vertx.core.Vertx;
9 | import io.vertx.core.json.JsonArray;
10 | import io.vertx.core.json.JsonObject;
11 | import org.junit.Before;
12 | import org.junit.Test;
13 | import org.junit.runner.RunWith;
14 | import org.mockito.Mock;
15 | import org.mockito.runners.MockitoJUnitRunner;
16 |
17 | import java.util.List;
18 |
19 | import static com.englishtown.vertx.cassandra.impl.JsonCassandraConfigurator.CONFIG_CASSANDRA;
20 | import static com.englishtown.vertx.cassandra.impl.JsonCassandraConfigurator.CONFIG_SEEDS;
21 | import static org.hamcrest.CoreMatchers.instanceOf;
22 | import static org.junit.Assert.*;
23 | import static org.mockito.Matchers.eq;
24 | import static org.mockito.Mockito.when;
25 |
26 | /**
27 | * Unit tests for {@link com.englishtown.vertx.cassandra.impl.EnvironmentCassandraConfigurator}
28 | */
29 | @RunWith(MockitoJUnitRunner.class)
30 | public class EnvironmentCassandraConfiguratorTest {
31 |
32 | JsonObject config = new JsonObject();
33 | JsonObject cassConfig;
34 |
35 | @Mock
36 | Vertx vertx;
37 | @Mock
38 | Context context;
39 | @Mock
40 | EnvironmentCassandraConfigurator.EnvVarDelegate envVarDelegate;
41 |
42 | @Before
43 | public void setUp() {
44 | when(context.config()).thenReturn(config);
45 | when(vertx.getOrCreateContext()).thenReturn(context);
46 |
47 | config.put(CONFIG_CASSANDRA, cassConfig = new JsonObject());
48 | }
49 |
50 |
51 | @Test
52 | public void testInitSeeds_Defaults() throws Exception {
53 |
54 | EnvironmentCassandraConfigurator configurator = new EnvironmentCassandraConfigurator(vertx, envVarDelegate);
55 | List seeds = configurator.getSeeds();
56 |
57 | assertNotNull(seeds);
58 | assertEquals(1, seeds.size());
59 | assertEquals("127.0.0.1", seeds.get(0));
60 | }
61 |
62 | @Test
63 | public void testInitSeeds() throws Exception {
64 |
65 | cassConfig.put(CONFIG_SEEDS, new JsonArray().add("127.0.0.5"));
66 | when(envVarDelegate.get(eq(EnvironmentCassandraConfigurator.ENV_VAR_SEEDS))).thenReturn("127.0.0.2|127.0.0.3|127.0.0.4");
67 |
68 | EnvironmentCassandraConfigurator configurator = new EnvironmentCassandraConfigurator(vertx, envVarDelegate);
69 | List seeds = configurator.getSeeds();
70 |
71 | assertNotNull(seeds);
72 | assertEquals(3, seeds.size());
73 | assertEquals("127.0.0.2", seeds.get(0));
74 | assertEquals("127.0.0.3", seeds.get(1));
75 | assertEquals("127.0.0.4", seeds.get(2));
76 | }
77 |
78 | @Test
79 | public void testInitPolicies() throws Exception {
80 |
81 | when(envVarDelegate.get(eq(EnvironmentCassandraConfigurator.ENV_VAR_LOCAL_DC))).thenReturn("LOCAL1");
82 |
83 | EnvironmentCassandraConfigurator configurator = new EnvironmentCassandraConfigurator(config, envVarDelegate);
84 | LoadBalancingPolicy loadBalancingPolicy = configurator.getLoadBalancingPolicy();
85 |
86 | assertThat(loadBalancingPolicy, instanceOf(DCAwareRoundRobinPolicy.class));
87 | }
88 |
89 | @Test
90 | public void testInitAuthProvider() throws Exception {
91 |
92 | EnvironmentCassandraConfigurator configurator = new EnvironmentCassandraConfigurator(config, envVarDelegate);
93 | AuthProvider authProvider = configurator.getAuthProvider();
94 |
95 | assertNull(authProvider);
96 |
97 | String username = "test";
98 | String password = "test_password";
99 | when(envVarDelegate.get(eq(EnvironmentCassandraConfigurator.ENV_VAR_USERNAME))).thenReturn(username);
100 | when(envVarDelegate.get(eq(EnvironmentCassandraConfigurator.ENV_VAR_PASSWORD))).thenReturn(password);
101 |
102 | configurator = new EnvironmentCassandraConfigurator(config, envVarDelegate);
103 | authProvider = configurator.getAuthProvider();
104 |
105 | assertThat(authProvider, instanceOf(PlainTextAuthProvider.class));
106 |
107 | }
108 | }
109 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/CassandraSessionIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration;
2 |
3 | import com.datastax.driver.core.BoundStatement;
4 | import com.datastax.driver.core.CodecRegistry;
5 | import com.datastax.driver.core.PreparedStatement;
6 | import com.datastax.driver.core.ProtocolVersion;
7 | import com.datastax.driver.core.RegularStatement;
8 | import com.datastax.driver.core.ResultSet;
9 | import com.datastax.driver.core.querybuilder.QueryBuilder;
10 | import com.google.common.util.concurrent.FutureCallback;
11 | import io.vertx.core.Context;
12 | import org.junit.Test;
13 |
14 | /**
15 | * Integration test for {@link com.englishtown.vertx.cassandra.CassandraSession}
16 | */
17 | public abstract class CassandraSessionIntegrationTest extends IntegrationTestBase {
18 |
19 | @Test
20 | public void testExecute() throws Exception {
21 |
22 | session.execute(createTestTableStatement);
23 |
24 | RegularStatement statement = QueryBuilder.select()
25 | .from(keyspace, "test")
26 | .where(QueryBuilder.eq("id", QueryBuilder.bindMarker()));
27 |
28 | PreparedStatement prepared = session.prepare(statement);
29 |
30 | BoundStatement bound = prepared.bind("123");
31 | ResultSet rs = session.execute(bound);
32 | assertNotNull(rs);
33 | testComplete();
34 | }
35 |
36 | @Test
37 | public void testExecuteAsync() throws Exception {
38 |
39 | vertx.runOnContext(aVoid -> {
40 |
41 | Context context = vertx.getOrCreateContext();
42 |
43 | session.executeAsync(createTestTableStatement, new FutureCallback() {
44 | @Override
45 | public void onSuccess(ResultSet result) {
46 | // Make sure we're on the right context
47 | assertEquals(context, vertx.getOrCreateContext());
48 | assertNotNull(result);
49 | testComplete();
50 | }
51 |
52 | @Override
53 | public void onFailure(Throwable t) {
54 | handleThrowable(t);
55 | }
56 | });
57 |
58 | });
59 |
60 | await();
61 |
62 | }
63 |
64 | }
65 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/IntegrationTestBase.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration;
2 |
3 | import com.datastax.driver.core.*;
4 | import com.datastax.driver.core.policies.LoadBalancingPolicy;
5 | import com.englishtown.promises.When;
6 | import com.englishtown.vertx.cassandra.CassandraSession;
7 | import com.englishtown.vertx.cassandra.keyspacebuilder.KeyspaceBuilder;
8 | import com.englishtown.vertx.cassandra.promises.WhenCassandraSession;
9 | import com.englishtown.vertx.cassandra.tablebuilder.CreateTable;
10 | import com.englishtown.vertx.cassandra.tablebuilder.TableBuilder;
11 | import com.google.common.base.Charsets;
12 | import com.google.common.io.Resources;
13 | import io.vertx.core.json.JsonObject;
14 | import io.vertx.test.core.VertxTestBase;
15 | import org.apache.cassandra.service.EmbeddedCassandraService;
16 | import org.junit.BeforeClass;
17 |
18 | import java.util.concurrent.CompletableFuture;
19 |
20 | /**
21 | * Cassandra base integration test class
22 | */
23 | public abstract class IntegrationTestBase extends VertxTestBase {
24 |
25 | private Locator locator;
26 | protected CassandraSession session;
27 | protected WhenCassandraSession whenSession;
28 | protected String keyspace;
29 | protected CreateTable createTestTableStatement;
30 | protected When when;
31 |
32 | public static final String TEST_CONFIG_FILE = "test_config.json";
33 | public static final String TEST_KEYSPACE = "test_vertx_mod_cass";
34 |
35 | private static EmbeddedCassandraService cassandraService = null;
36 |
37 | protected abstract Locator createLocator();
38 |
39 | @BeforeClass
40 | public static void beforeClass() throws Exception {
41 | if (cassandraService == null) {
42 | String embedded = System.getProperty("test.embedded", "");
43 | if (!"true".equals(embedded)) {
44 | return;
45 | }
46 | System.setProperty("cassandra.storagedir", "target/cassandra");
47 | cassandraService = new EmbeddedCassandraService();
48 | cassandraService.start();
49 | }
50 | }
51 |
52 | /**
53 | * Override to run additional initialization before your integration tests run
54 | */
55 | @Override
56 | public void setUp() throws Exception {
57 | super.setUp();
58 | locator = createLocator();
59 |
60 | CompletableFuture future = new CompletableFuture<>();
61 |
62 | vertx.runOnContext(aVoid -> {
63 |
64 | // Load the test config file, if we have one
65 | JsonObject config = loadConfig();
66 | vertx.getOrCreateContext().config().mergeIn(config);
67 |
68 | // String dateTime = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date());
69 | keyspace = TEST_KEYSPACE; //dateTime;
70 |
71 | session = getInstance(CassandraSession.class);
72 | when = getInstance(When.class);
73 | whenSession = getInstance(WhenCassandraSession.class);
74 |
75 | session.onReady(result -> {
76 | if (result.failed()) {
77 | future.completeExceptionally(result.cause());
78 | return;
79 | }
80 |
81 | Metadata metadata = session.getMetadata();
82 | KeyspaceMetadata keyspaceMetadata = metadata.getKeyspace(keyspace);
83 | if (keyspaceMetadata != null) {
84 | for (TableMetadata tableMetadata : keyspaceMetadata.getTables()) {
85 | session.execute(TableBuilder.drop(keyspace, tableMetadata.getName()).ifExists());
86 | }
87 | } else {
88 | createKeyspace(metadata);
89 | }
90 |
91 | createTestTableStatement = TableBuilder.create(keyspace, "test")
92 | .ifNotExists()
93 | .column("id", "text")
94 | .column("value", "text")
95 | .primaryKey("id");
96 |
97 | future.complete(null);
98 | });
99 | });
100 |
101 | future.get();
102 | }
103 |
104 | protected T getInstance(Class clazz) {
105 | return locator.getInstance(clazz);
106 | }
107 |
108 | private void createKeyspace(Metadata metadata) {
109 |
110 | Statement createKeyspaceStatement = null;
111 |
112 | // Find out which node is closest and use that for the networktopologystrategy
113 | LoadBalancingPolicy lbPolicy = session.getCluster().getConfiguration().getPolicies().getLoadBalancingPolicy();
114 | for (Host host : metadata.getAllHosts()) {
115 | if (lbPolicy.distance(host) == HostDistance.LOCAL) {
116 | createKeyspaceStatement = KeyspaceBuilder.create(keyspace)
117 | .ifNotExists()
118 | .networkTopologyStrategy()
119 | .dc(host.getDatacenter(), 1);
120 | break;
121 | }
122 | }
123 |
124 | if (createKeyspaceStatement == null) {
125 | fail("Could not find a local host for the test");
126 | return;
127 | }
128 |
129 | session.execute(createKeyspaceStatement);
130 |
131 | }
132 |
133 | private JsonObject loadConfig() {
134 | try {
135 | return new JsonObject(Resources.toString(Resources.getResource(TEST_CONFIG_FILE), Charsets.UTF_8));
136 | } catch (Exception e) {
137 | return new JsonObject();
138 | }
139 | }
140 |
141 | /**
142 | * Vert.x calls the stop method when the verticle is undeployed.
143 | * Put any cleanup code for your verticle in here
144 | */
145 | @Override
146 | public void tearDown() throws Exception {
147 | try {
148 | if (session != null) {
149 | session.close();
150 | }
151 | } catch (Exception e) {
152 | e.printStackTrace();
153 | }
154 |
155 | super.tearDown();
156 | }
157 |
158 | protected void handleThrowable(Throwable t) {
159 | t.printStackTrace();
160 | fail();
161 | }
162 |
163 | }
164 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/Locator.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration;
2 |
3 | /**
4 | * Created by adriangonzalez on 5/29/15.
5 | */
6 | public interface Locator {
7 |
8 | T getInstance(Class clazz);
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/TableBuilderIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration;
2 |
3 | import com.datastax.driver.core.Statement;
4 | import com.datastax.driver.core.TableMetadata;
5 | import com.datastax.driver.core.exceptions.QueryValidationException;
6 | import com.englishtown.vertx.cassandra.tablebuilder.AlterTable;
7 | import com.englishtown.vertx.cassandra.tablebuilder.CreateTable;
8 | import com.englishtown.vertx.cassandra.tablebuilder.TableBuilder;
9 | import org.junit.Test;
10 |
11 | import java.util.List;
12 |
13 | /**
14 | * Integration tests for {@link com.englishtown.vertx.cassandra.tablebuilder.TableBuilder}
15 | */
16 | public abstract class TableBuilderIntegrationTest extends IntegrationTestBase {
17 |
18 | @Test
19 | public void testTableBuilder() throws Exception {
20 |
21 | assertNotNull(session.getMetadata().getKeyspace(keyspace));
22 |
23 | String table = "test_table";
24 | Statement statement;
25 |
26 | assertNull(session.getMetadata().getKeyspace(keyspace).getTable(table));
27 |
28 | // Create the table
29 | statement = TableBuilder.create(keyspace, table)
30 | .column("col1", "text")
31 | .column("col2", "text")
32 | .primaryKey("col1");
33 |
34 | session.execute(statement);
35 |
36 | assertNotNull(session.getMetadata().getKeyspace(keyspace).getTable(table));
37 |
38 | try {
39 | session.execute(statement);
40 | fail("Table already exists, create should have throw AlreadyExistsException");
41 | } catch (QueryValidationException e) {
42 | // Expected
43 | }
44 |
45 | // Should not fail with the "IF NOT EXISTS" statement
46 | statement = TableBuilder.create(keyspace, table)
47 | .ifNotExists()
48 | .column("col1", "text")
49 | .column("col2", "text")
50 | .primaryKey("col1");
51 |
52 | session.execute(statement);
53 |
54 | CreateTable createTable = TableBuilder.create(keyspace, table)
55 | .column("col1", "text")
56 | .column("col2", "text")
57 | .column("col3", "int")
58 | .column("col4", "boolean")
59 | .column("col5", "uuid")
60 | .primaryKey("col1");
61 |
62 | TableMetadata tableMetadata = session.getMetadata().getKeyspace(keyspace).getTable(table);
63 | List alterStatements = TableBuilder.alter(tableMetadata, createTable);
64 |
65 | for (AlterTable alterTable : alterStatements) {
66 | session.execute(alterTable);
67 | }
68 |
69 | tableMetadata = session.getMetadata().getKeyspace(keyspace).getTable(table);
70 | assertEquals(5, tableMetadata.getColumns().size());
71 |
72 | statement = TableBuilder.drop(keyspace, table);
73 | session.execute(statement);
74 |
75 | statement = TableBuilder.drop(keyspace, table)
76 | .ifExists();
77 | session.execute(statement);
78 |
79 | try {
80 | statement = TableBuilder.drop(keyspace, table);
81 | session.execute(statement);
82 | fail("Table should not exist, drop should have throw InvalidQueryException");
83 | } catch (QueryValidationException e) {
84 | // Expected
85 | }
86 |
87 | testComplete();
88 |
89 | }
90 |
91 | }
92 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/WhenCassandraSessionIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration;
2 |
3 | import com.datastax.driver.core.Statement;
4 | import com.englishtown.vertx.cassandra.tablebuilder.TableBuilder;
5 | import io.vertx.core.Context;
6 | import org.junit.Test;
7 |
8 | /**
9 | * Integration test for {@link com.englishtown.vertx.cassandra.CassandraSession}
10 | */
11 | public abstract class WhenCassandraSessionIntegrationTest extends IntegrationTestBase {
12 |
13 | @Test
14 | public void testExecuteAsync() throws Exception {
15 |
16 | vertx.runOnContext(aVoid -> {
17 |
18 | final Context context = vertx.getOrCreateContext();
19 |
20 | whenSession.executeAsync(createTestTableStatement)
21 | .then(value -> {
22 | // Make sure we're on the right context
23 | assertEquals(context, vertx.getOrCreateContext());
24 | assertNotNull(value);
25 |
26 | Statement statement = TableBuilder.create(keyspace, "test")
27 | .column("id", "text")
28 | .primaryKey("id");
29 |
30 | // This promise will reject
31 | return whenSession.executeAsync(statement);
32 | })
33 | .then(value -> {
34 | // Should have reject, keyspace already exists
35 | fail();
36 | return null;
37 | },
38 | value -> {
39 | // Make sure we're on the right context
40 | assertEquals(context, vertx.getOrCreateContext());
41 | assertNotNull(value);
42 | return null;
43 | })
44 | .then(value -> {
45 | testComplete();
46 | return null;
47 | })
48 | .otherwise(t -> {
49 | handleThrowable(t);
50 | return null;
51 | });
52 |
53 | });
54 |
55 | await();
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/guice/GuiceCassandraSessionIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration.guice;
2 |
3 | import com.englishtown.vertx.cassandra.integration.CassandraSessionIntegrationTest;
4 | import com.englishtown.vertx.cassandra.integration.Locator;
5 |
6 | /**
7 | * Guice version of {@link CassandraSessionIntegrationTest}
8 | */
9 | public class GuiceCassandraSessionIntegrationTest extends CassandraSessionIntegrationTest {
10 |
11 | @Override
12 | protected Locator createLocator() {
13 | return new GuiceLocator(vertx);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/guice/GuiceLocator.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration.guice;
2 |
3 | import com.englishtown.vertx.cassandra.guice.GuiceWhenCassandraBinder;
4 | import com.englishtown.vertx.cassandra.integration.Locator;
5 | import com.englishtown.vertx.guice.GuiceVertxBinder;
6 | import com.englishtown.vertx.promises.guice.GuiceWhenBinder;
7 | import com.google.inject.Guice;
8 | import com.google.inject.Injector;
9 | import com.google.inject.Module;
10 | import io.vertx.core.Vertx;
11 |
12 | import java.util.ArrayList;
13 | import java.util.Collections;
14 | import java.util.List;
15 |
16 | /**
17 | * Guice {@link Locator} implementation
18 | */
19 | public class GuiceLocator implements Locator {
20 |
21 | private Injector injector;
22 |
23 | public GuiceLocator(Vertx vertx, Module... modules) {
24 |
25 | List list = new ArrayList<>();
26 | list.add(new GuiceWhenBinder());
27 | list.add(new GuiceWhenCassandraBinder());
28 | list.add(new GuiceVertxBinder(vertx));
29 |
30 | if (modules != null) {
31 | Collections.addAll(list, modules);
32 | }
33 |
34 | injector = Guice.createInjector(list);
35 |
36 | }
37 |
38 | public Injector getInjector() {
39 | return injector;
40 | }
41 |
42 | @Override
43 | public T getInstance(Class clazz) {
44 | return injector.getInstance(clazz);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/guice/GuiceTableBuilderIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration.guice;
2 |
3 | import com.englishtown.vertx.cassandra.integration.Locator;
4 | import com.englishtown.vertx.cassandra.integration.TableBuilderIntegrationTest;
5 |
6 | /**
7 | * Guice version of {@link TableBuilderIntegrationTest}
8 | */
9 | public class GuiceTableBuilderIntegrationTest extends TableBuilderIntegrationTest {
10 |
11 | @Override
12 | protected Locator createLocator() {
13 | return new GuiceLocator(vertx);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/guice/GuiceWhenCassandraSessionIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration.guice;
2 |
3 | import com.englishtown.vertx.cassandra.integration.Locator;
4 | import com.englishtown.vertx.cassandra.integration.WhenCassandraSessionIntegrationTest;
5 |
6 | /**
7 | * Guice version of {@link WhenCassandraSessionIntegrationTest}
8 | */
9 | public class GuiceWhenCassandraSessionIntegrationTest extends WhenCassandraSessionIntegrationTest {
10 |
11 | @Override
12 | protected Locator createLocator() {
13 | return new GuiceLocator(vertx);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/hk2/HK2CassandraSessionIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration.hk2;
2 |
3 | import com.englishtown.vertx.cassandra.integration.CassandraSessionIntegrationTest;
4 | import com.englishtown.vertx.cassandra.integration.Locator;
5 |
6 | /**
7 | * HK2 version of {@link CassandraSessionIntegrationTest}
8 | */
9 | public class HK2CassandraSessionIntegrationTest extends CassandraSessionIntegrationTest {
10 |
11 | @Override
12 | protected Locator createLocator() {
13 | return new HK2Locator(vertx);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/hk2/HK2Locator.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration.hk2;
2 |
3 | import com.englishtown.vertx.cassandra.hk2.HK2WhenCassandraBinder;
4 | import com.englishtown.vertx.cassandra.integration.Locator;
5 | import com.englishtown.vertx.hk2.HK2VertxBinder;
6 | import com.englishtown.vertx.promises.hk2.HK2WhenBinder;
7 | import io.vertx.core.Vertx;
8 | import org.glassfish.hk2.api.ServiceLocator;
9 | import org.glassfish.hk2.api.ServiceLocatorFactory;
10 | import org.glassfish.hk2.utilities.Binder;
11 | import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
12 |
13 | /**
14 | * HK2 {@link Locator} implementation
15 | */
16 | public class HK2Locator implements Locator {
17 |
18 | private ServiceLocator locator;
19 |
20 | public HK2Locator(Vertx vertx, Binder... binders) {
21 |
22 | locator = ServiceLocatorFactory.getInstance().create(null);
23 | ServiceLocatorUtilities.bind(locator,
24 | new HK2WhenBinder(),
25 | new HK2WhenCassandraBinder(),
26 | new HK2VertxBinder(vertx));
27 |
28 | if (binders != null) {
29 | ServiceLocatorUtilities.bind(locator, binders);
30 | }
31 |
32 | }
33 |
34 | @Override
35 | public T getInstance(Class clazz) {
36 | return locator.getService(clazz);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/hk2/HK2TableBuilderIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration.hk2;
2 |
3 | import com.englishtown.vertx.cassandra.integration.Locator;
4 | import com.englishtown.vertx.cassandra.integration.TableBuilderIntegrationTest;
5 |
6 | /**
7 | * HK2 version of {@link TableBuilderIntegrationTest}
8 | */
9 | public class HK2TableBuilderIntegrationTest extends TableBuilderIntegrationTest {
10 |
11 | @Override
12 | protected Locator createLocator() {
13 | return new HK2Locator(vertx);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/integration/hk2/HK2WhenCassandraSessionIntegrationTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.integration.hk2;
2 |
3 | import com.englishtown.vertx.cassandra.integration.Locator;
4 | import com.englishtown.vertx.cassandra.integration.WhenCassandraSessionIntegrationTest;
5 |
6 | /**
7 | * HK2 version of {@link WhenCassandraSessionIntegrationTest}
8 | */
9 | public class HK2WhenCassandraSessionIntegrationTest extends WhenCassandraSessionIntegrationTest {
10 |
11 | @Override
12 | protected Locator createLocator() {
13 | return new HK2Locator(vertx);
14 | }
15 |
16 | }
17 |
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/keyspacebuilder/AlterKeyspaceTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.keyspacebuilder;
2 |
3 | import com.datastax.driver.core.Statement;
4 | import org.junit.Test;
5 |
6 | import static org.junit.Assert.assertEquals;
7 |
8 | public class AlterKeyspaceTest {
9 |
10 | @Test
11 | public void testAlterKeyspace_SimpleStrategy() throws Exception {
12 |
13 | String name = "test_keyspace";
14 |
15 | Statement alterKeyspace = KeyspaceBuilder.alter(name)
16 | .simpleStrategy(3);
17 |
18 | String cql = alterKeyspace.toString();
19 | assertEquals("ALTER KEYSPACE test_keyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }", cql);
20 |
21 | }
22 |
23 | @Test
24 | public void testCreateKeyspace_NetworkTopologyStrategy() throws Exception {
25 |
26 | String name = "test_keyspace";
27 |
28 | Statement createKeyspace = KeyspaceBuilder.alter(name)
29 | .networkTopologyStrategy()
30 | .dc("dc1", 3)
31 | .dc("dc2", 2)
32 | .dc("dc3", 1);
33 |
34 | String cql = createKeyspace.toString();
35 | assertEquals("ALTER KEYSPACE test_keyspace WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2, 'dc3' : 1 }", cql);
36 |
37 | }
38 |
39 | }
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/keyspacebuilder/CreateKeyspaceTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.keyspacebuilder;
2 |
3 | import com.datastax.driver.core.Statement;
4 | import org.junit.Test;
5 |
6 | import static org.junit.Assert.assertEquals;
7 |
8 | public class CreateKeyspaceTest {
9 |
10 | @Test
11 | public void testCreateKeyspace_SimpleStrategy() throws Exception {
12 |
13 | String name = "test_keyspace";
14 |
15 | Statement createKeyspace = KeyspaceBuilder.create(name)
16 | .ifNotExists()
17 | .simpleStrategy(3);
18 |
19 | String cql = createKeyspace.toString();
20 | assertEquals("CREATE KEYSPACE IF NOT EXISTS test_keyspace WITH REPLICATION = { 'class' : 'SimpleStrategy', 'replication_factor' : 3 }", cql);
21 |
22 | }
23 |
24 | @Test
25 | public void testCreateKeyspace_NetworkTopologyStrategy() throws Exception {
26 |
27 | String name = "test_keyspace";
28 |
29 | Statement createKeyspace = KeyspaceBuilder.create(name)
30 | .networkTopologyStrategy()
31 | .dc("dc1", 3)
32 | .dc("dc2", 2)
33 | .dc("dc3", 1);
34 |
35 | String cql = createKeyspace.toString();
36 | assertEquals("CREATE KEYSPACE test_keyspace WITH REPLICATION = { 'class' : 'NetworkTopologyStrategy', 'dc1' : 3, 'dc2' : 2, 'dc3' : 1 }", cql);
37 |
38 | }
39 |
40 | }
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/keyspacebuilder/DropKeyspaceTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.keyspacebuilder;
2 |
3 | import com.datastax.driver.core.Statement;
4 | import org.junit.Test;
5 |
6 | import static org.junit.Assert.assertEquals;
7 |
8 | public class DropKeyspaceTest {
9 |
10 | String keyspace = "test_keyspace";
11 |
12 | @Test
13 | public void testDropKeyspace() throws Exception {
14 |
15 | Statement statement = KeyspaceBuilder.drop(keyspace);
16 | String cql = statement.toString();
17 |
18 | assertEquals("DROP KEYSPACE test_keyspace", cql);
19 |
20 | }
21 |
22 | @Test
23 | public void testDropKeyspace_IfExists() throws Exception {
24 |
25 | Statement statement = KeyspaceBuilder.drop(keyspace)
26 | .ifExists();
27 | String cql = statement.toString();
28 |
29 | assertEquals("DROP KEYSPACE IF EXISTS test_keyspace", cql);
30 |
31 | }
32 |
33 | }
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/promises/impl/DefaultWhenCassandraSessionTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.promises.impl;
2 |
3 | import com.englishtown.promises.*;
4 | import com.englishtown.vertx.cassandra.CassandraSession;
5 | import io.vertx.core.AsyncResult;
6 | import io.vertx.core.Future;
7 | import io.vertx.core.Handler;
8 | import io.vertx.core.Vertx;
9 | import io.vertx.core.spi.FutureFactory;
10 | import org.junit.Before;
11 | import org.junit.Test;
12 | import org.junit.runner.RunWith;
13 | import org.mockito.ArgumentCaptor;
14 | import org.mockito.Captor;
15 | import org.mockito.Mock;
16 | import org.mockito.runners.MockitoJUnitRunner;
17 |
18 | import static org.junit.Assert.assertEquals;
19 | import static org.mockito.Mockito.verify;
20 |
21 | /**
22 | * Unit tests for {@link DefaultWhenCassandraSession}
23 | */
24 | @RunWith(MockitoJUnitRunner.class)
25 | public class DefaultWhenCassandraSessionTest {
26 |
27 | @Mock
28 | private CassandraSession cassandraSession;
29 | @Mock
30 | private Vertx vertx;
31 | @Captor
32 | private ArgumentCaptor>> onReadyCaptor;
33 |
34 | private When when;
35 | private DefaultWhenCassandraSession whenCassandraSession;
36 |
37 | @Before
38 | public void setUp() throws Exception {
39 | when = WhenFactory.createSync();
40 | whenCassandraSession = new DefaultWhenCassandraSession(cassandraSession, when, vertx);
41 | }
42 |
43 | @Test
44 | public void testReady() throws Exception {
45 |
46 | Promise p = whenCassandraSession.ready();
47 | State state = p.inspect();
48 | assertEquals(HandlerState.PENDING, state.getState());
49 |
50 | verify(cassandraSession).onReady(onReadyCaptor.capture());
51 | onReadyCaptor.getValue().handle(Future.succeededFuture());
52 |
53 | state = p.inspect();
54 | assertEquals(HandlerState.FULFILLED, state.getState());
55 |
56 | }
57 |
58 | @Test
59 | public void testReadyReject() throws Exception {
60 |
61 | Promise p = whenCassandraSession.ready();
62 | State state = p.inspect();
63 | assertEquals(HandlerState.PENDING, state.getState());
64 |
65 | verify(cassandraSession).onReady(onReadyCaptor.capture());
66 | onReadyCaptor.getValue().handle(Future.failedFuture("Test fail"));
67 |
68 | state = p.inspect();
69 | assertEquals(HandlerState.REJECTED, state.getState());
70 |
71 | }
72 |
73 | }
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/tablebuilder/AlterTableTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.tablebuilder;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class AlterTableTest {
8 |
9 | @Test
10 | public void testAlter() throws Exception {
11 | AlterTable alter = TableBuilder.alter("test_keyspace", "test_table")
12 | .alterColumn("col1", "text");
13 |
14 | String cql = alter.getQueryString();
15 | assertEquals("ALTER TABLE test_keyspace.test_table ALTER col1 TYPE text", cql);
16 | }
17 |
18 | @Test
19 | public void testAdd() throws Exception {
20 | AlterTable alter = TableBuilder.alter("test_keyspace", "test_table")
21 | .addColumn("col1", "text");
22 |
23 | String cql = alter.getQueryString();
24 | assertEquals("ALTER TABLE test_keyspace.test_table ADD col1 text", cql);
25 | }
26 |
27 | @Test
28 | public void testDrop() throws Exception {
29 | AlterTable alter = TableBuilder.alter("test_keyspace", "test_table")
30 | .dropColumn("col1");
31 |
32 | String cql = alter.getQueryString();
33 | assertEquals("ALTER TABLE test_keyspace.test_table DROP col1", cql);
34 | }
35 |
36 | @Test
37 | public void testRename() throws Exception {
38 | AlterTable alter = TableBuilder.alter("test_keyspace", "test_table")
39 | .renameColumn("col1", "col2");
40 |
41 | String cql = alter.getQueryString();
42 | assertEquals("ALTER TABLE test_keyspace.test_table RENAME col1 TO col2", cql);
43 | }
44 | }
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/tablebuilder/CreateTableTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.tablebuilder;
2 |
3 | import org.junit.Before;
4 | import org.junit.Test;
5 |
6 | import static org.junit.Assert.assertEquals;
7 |
8 | public class CreateTableTest {
9 |
10 | @Before
11 | public void setUp() throws Exception {
12 | }
13 |
14 | @Test
15 | public void testCreateTable() throws Exception {
16 |
17 | CreateTable table = TableBuilder.create("test_keyspace", "test_table")
18 | .ifNotExists()
19 | .column("col1", "text")
20 | .column("col2", "int")
21 | .staticColumn("col3", "blob")
22 | .primaryKeys("col1", "col2");
23 |
24 | String cql = table.getQueryString();
25 | assertEquals("CREATE TABLE IF NOT EXISTS test_keyspace.test_table (col1 text, col2 int, col3 blob STATIC, PRIMARY KEY(col1, col2))", cql);
26 |
27 | }
28 |
29 | @Test
30 | public void testCreateTable_Composite_Partition_Key() throws Exception {
31 |
32 | CreateTable table = TableBuilder.create("test_keyspace", "test_table")
33 | .column("col1", "text")
34 | .column("col2", "int")
35 | .column("col3", "blob")
36 | .column("col4", "uuid")
37 | .primaryKey("col1", PrimaryKeyType.PARTITIONING)
38 | .primaryKey("col2", PrimaryKeyType.PARTITIONING)
39 | .primaryKey("col3", PrimaryKeyType.CLUSTERING)
40 | .primaryKey("col4");
41 |
42 | String cql = table.getQueryString();
43 | assertEquals("CREATE TABLE test_keyspace.test_table (col1 text, col2 int, col3 blob, col4 uuid, PRIMARY KEY((col1, col2), col3, col4))", cql);
44 |
45 | }
46 |
47 | @Test
48 | public void testColumns() throws Exception {
49 |
50 | CreateTable table = TableBuilder.create("test_keyspace", "test_table")
51 | .columns(new String[]{"col1", "col2", "col3"}, new String[]{"text", "int", "blob"})
52 | .column("col4", "text")
53 | .column("col3", "text")
54 | .column("col1", "int")
55 | .primaryKey("col1");
56 |
57 | String cql = table.getQueryString();
58 | assertEquals("CREATE TABLE test_keyspace.test_table (col1 int, col2 int, col3 text, col4 text, PRIMARY KEY(col1))", cql);
59 |
60 | }
61 |
62 | }
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/tablebuilder/DropTableTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.tablebuilder;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | public class DropTableTest {
8 |
9 | @Test
10 | public void testDropTable() throws Exception {
11 |
12 | DropTable table = TableBuilder.drop("test_keyspace", "test_table");
13 |
14 | String cql = table.getQueryString();
15 | assertEquals("DROP TABLE test_keyspace.test_table", cql);
16 |
17 | }
18 |
19 | @Test
20 | public void testIfExists() throws Exception {
21 |
22 | DropTable table = TableBuilder.drop("test_keyspace", "test_table").ifExists();
23 |
24 | String cql = table.getQueryString();
25 | assertEquals("DROP TABLE IF EXISTS test_keyspace.test_table", cql);
26 |
27 | }
28 |
29 | }
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/java/com/englishtown/vertx/cassandra/tablebuilder/TableBuilderTest.java:
--------------------------------------------------------------------------------
1 | package com.englishtown.vertx.cassandra.tablebuilder;
2 |
3 | import com.datastax.driver.core.AbstractTableMetadata;
4 | import com.datastax.driver.core.ColumnMetadata;
5 | import com.datastax.driver.core.DataType;
6 | import org.junit.Before;
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 | import org.mockito.Mock;
10 | import org.mockito.runners.MockitoJUnitRunner;
11 |
12 | import java.util.HashMap;
13 | import java.util.List;
14 | import java.util.Map;
15 |
16 | import static org.junit.Assert.assertEquals;
17 | import static org.mockito.Mockito.when;
18 |
19 | @RunWith(MockitoJUnitRunner.class)
20 | public class TableBuilderTest {
21 |
22 | private TestTableMetadata existing;
23 | @Mock
24 | private ColumnMetadata col1;
25 | @Mock
26 | private ColumnMetadata col2;
27 |
28 | @Before
29 | public void setUp() throws Exception {
30 |
31 | existing = new TestTableMetadata();
32 | existing.getColumnMap().put("col1", col1);
33 | existing.getColumnMap().put("col2", col2);
34 |
35 | when(col1.getType()).thenReturn(DataType.text());
36 | when(col2.getType()).thenReturn(DataType.cint());
37 |
38 | }
39 |
40 | @Test
41 | public void testAlter() throws Exception {
42 |
43 | CreateTable desired = TableBuilder.create("test_keyspace", "test_table")
44 | .column("col1", "text")
45 | .column("col2", "bigint")
46 | .column("col3", "int")
47 | .column("col4", "text")
48 | .primaryKey("col1");
49 |
50 | List statements = TableBuilder.alter(existing, desired);
51 |
52 | assertEquals(3, statements.size());
53 | assertEquals("ALTER TABLE test_keyspace.test_table ALTER col2 TYPE bigint", statements.get(0).toString());
54 | assertEquals("ALTER TABLE test_keyspace.test_table ADD col3 int", statements.get(1).toString());
55 | assertEquals("ALTER TABLE test_keyspace.test_table ADD col4 text", statements.get(2).toString());
56 |
57 | }
58 |
59 | private static class TestTableMetadata extends AbstractTableMetadata {
60 |
61 | public TestTableMetadata() {
62 | super(null, null, null, null, null, new HashMap<>(), null, null, null);
63 | }
64 |
65 | @Override
66 | protected String asCQLQuery(boolean formatted) {
67 | throw new UnsupportedOperationException();
68 | }
69 |
70 | public Map getColumnMap() {
71 | return columns;
72 | }
73 | }
74 | }
--------------------------------------------------------------------------------
/vertx-cassandra/src/test/resources/test_config.json:
--------------------------------------------------------------------------------
1 | {
2 | "cassandra": {
3 | "seeds": [${test.cassandra.seeds}],
4 | "port": ${test.cassandra.port},
5 | "auth": {
6 | "username": "cassandra",
7 | "password": "cassandra"
8 | }
9 | }
10 | }
--------------------------------------------------------------------------------