kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 136e41559246ff0cbace79b30c69320ae1363e689a79909313fd2f4b472e5043 |
|---|---|
| Author | alramlechner <alram.lechner@gmx.at> · 2016-03-03 11:05 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2016-04-26 17:02 +02:00 |
| Parents | 420b015e3f44 |
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 @@ | ||
| 59 | 59 | accepts("print-delay", "The delay in seconds at which to report on the console").withRequiredArg().ofType(Integer.class).defaultsTo(5); |
| 60 | 60 | accepts("compression", "Use compression (SNAPPY)"); |
| 61 | 61 | 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); | |
| 62 | 64 | }}; |
| 63 | 65 | String msg = "Where <generator> can be one of " + generators.keySet() + '\n' |
| 64 | 66 | + "You can get more help on a particular generator with: stress <generator> -h"; |
| @@ -198,6 +200,7 @@ | ||
| 198 | 200 | |
| 199 | 201 | int requests = options.has("n") ? (Integer) options.valueOf("n") : -1; |
| 200 | 202 | int concurrency = (Integer) options.valueOf("t"); |
| 203 | + ConsistencyLevel consistencyLevel = (ConsistencyLevel) options.valueOf("consistency-level"); | |
| 201 | 204 | |
| 202 | 205 | String reportFileName = (String) options.valueOf("report-file"); |
| 203 | 206 | |
| @@ -223,6 +226,7 @@ | ||
| 223 | 226 | System.out.println(" mode: " + (async ? "asynchronous" : "blocking")); |
| 224 | 227 | System.out.println(" per-host connections: " + maxConnections); |
| 225 | 228 | System.out.println(" compression: " + options.has("compression")); |
| 229 | + System.out.println(" consistency-level: " + consistencyLevel.name()); | |
| 226 | 230 | |
| 227 | 231 | try { |
| 228 | 232 | // Create session to hosts |
| @@ -230,6 +234,7 @@ | ||
| 230 | 234 | .addContactPoints(String.valueOf(options.valueOf("ip"))) |
| 231 | 235 | .withPoolingOptions(pools) |
| 232 | 236 | .withSocketOptions(new SocketOptions().setTcpNoDelay(true)) |
| 237 | + .withQueryOptions(new QueryOptions().setConsistencyLevel(consistencyLevel)) | |
| 233 | 238 | .build(); |
| 234 | 239 | |
| 235 | 240 | if (options.has("compression")) |