Elffuss BraidHub

kikocis/java-driver public

JAVA-1108 add param to stress app, to set consistency level
Changeset136e41559246ff0cbace79b30c69320ae1363e689a79909313fd2f4b472e5043
Authoralramlechner <alram.lechner@gmx.at> · 2016-03-03 11:05 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2016-04-26 17:02 +02:00
Parents420b015e3f44

Browse the files at this changeset

2 files changed

added driver-examples/stress/src/main/java/com/datastax/driver/stress/ConsistencyLevelConverter.java +45 −0
@@ -0,0 +1,45 @@
1+/*
2+ * Copyright (C) 2012-2015 DataStax Inc.
3+ *
4+ * Licensed under the Apache License, Version 2.0 (the "License");
5+ * you may not use this file except in compliance with the License.
6+ * You may obtain a copy of the License at
7+ *
8+ * http://www.apache.org/licenses/LICENSE-2.0
9+ *
10+ * Unless required by applicable law or agreed to in writing, software
11+ * distributed under the License is distributed on an "AS IS" BASIS,
12+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ * See the License for the specific language governing permissions and
14+ * limitations under the License.
15+ */
16+package com.datastax.driver.stress;
17+
18+import com.datastax.driver.core.ConsistencyLevel;
19+import joptsimple.ValueConverter;
20+
21+/**
22+ * Created by Alram.Lechner on 03.03.2016.
23+ */
24+public class ConsistencyLevelConverter implements ValueConverter<ConsistencyLevel> {
25+
26+ @Override
27+ public ConsistencyLevel convert(String value) {
28+ return ConsistencyLevel.valueOf(value);
29+ }
30+
31+ @Override
32+ public Class<ConsistencyLevel> valueType() {
33+ return ConsistencyLevel.class;
34+ }
35+
36+ @Override
37+ public String valuePattern() {
38+ StringBuilder pattern = new StringBuilder();
39+ for (ConsistencyLevel level : ConsistencyLevel.values()) {
40+ pattern.append("(").append(level.name()).append(")|");
41+ }
42+ pattern.setLength(pattern.length() - 1);
43+ return pattern.toString();
44+ }
45+}
modified driver-examples/stress/src/main/java/com/datastax/driver/stress/Stress.java +5 −0
@@ -59,6 +59,8 @@
5959 accepts("print-delay", "The delay in seconds at which to report on the console").withRequiredArg().ofType(Integer.class).defaultsTo(5);
6060 accepts("compression", "Use compression (SNAPPY)");
6161 accepts("connections-per-host", "The number of connections per hosts (default: based on the number of threads)").withRequiredArg().ofType(Integer.class);
62+ accepts("consistency-level", "Consistency level").withRequiredArg().withValuesConvertedBy(new ConsistencyLevelConverter())
63+ .ofType(ConsistencyLevel.class).defaultsTo(ConsistencyLevel.LOCAL_ONE);
6264 }};
6365 String msg = "Where <generator> can be one of " + generators.keySet() + '\n'
6466 + "You can get more help on a particular generator with: stress <generator> -h";
@@ -198,6 +200,7 @@
198200
199201 int requests = options.has("n") ? (Integer) options.valueOf("n") : -1;
200202 int concurrency = (Integer) options.valueOf("t");
203+ ConsistencyLevel consistencyLevel = (ConsistencyLevel) options.valueOf("consistency-level");
201204
202205 String reportFileName = (String) options.valueOf("report-file");
203206
@@ -223,6 +226,7 @@
223226 System.out.println(" mode: " + (async ? "asynchronous" : "blocking"));
224227 System.out.println(" per-host connections: " + maxConnections);
225228 System.out.println(" compression: " + options.has("compression"));
229+ System.out.println(" consistency-level: " + consistencyLevel.name());
226230
227231 try {
228232 // Create session to hosts
@@ -230,6 +234,7 @@
230234 .addContactPoints(String.valueOf(options.valueOf("ip")))
231235 .withPoolingOptions(pools)
232236 .withSocketOptions(new SocketOptions().setTcpNoDelay(true))
237+ .withQueryOptions(new QueryOptions().setConsistencyLevel(consistencyLevel))
233238 .build();
234239
235240 if (options.has("compression"))