Skip to content

Commit c94de4e

Browse files
committedFeb 10, 2016
adding tenfields activities and RandomStringRangeGenerator
1 parent fbd3f7a commit c94de4e

File tree

6 files changed

+191
-0
lines changed

6 files changed

+191
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
*
3+
* Copyright 2015 Jonathan Shook
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package com.metawiring.load.generators;
20+
21+
import com.metawiring.load.generator.FastForwardableGenerator;
22+
import com.metawiring.load.generator.ThreadsafeGenerator;
23+
import org.joda.time.format.DateTimeFormatter;
24+
25+
import java.util.concurrent.atomic.AtomicLong;
26+
27+
28+
public class CycleNumberStringGenerator implements FastForwardableGenerator<String>,ThreadsafeGenerator {
29+
30+
private AtomicLong seq = new AtomicLong(0l);
31+
private DateTimeFormatter formatter;
32+
33+
public CycleNumberStringGenerator() {
34+
}
35+
36+
@Override
37+
public String get() {
38+
long outval = seq.incrementAndGet();
39+
return String.valueOf(outval);
40+
}
41+
42+
@Override
43+
public void fastForward(long fastForwardTo) {
44+
seq = new AtomicLong(fastForwardTo);
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
*
3+
* Copyright 2015 Jonathan Shook
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package com.metawiring.load.generators;
20+
21+
import com.metawiring.load.generator.Generator;
22+
import org.apache.commons.math3.random.MersenneTwister;
23+
24+
public class RandomStringRangeGenerator implements Generator<String> {
25+
private MersenneTwister theTwister = new MersenneTwister(System.nanoTime());
26+
private long min;
27+
private long max;
28+
private long length;
29+
30+
public RandomStringRangeGenerator(long min, long max) {
31+
this.min = min;
32+
this.max = max;
33+
this.length = max - min;
34+
}
35+
36+
public RandomStringRangeGenerator(String min, String max) {
37+
this(Long.valueOf(min), Long.valueOf(max));
38+
}
39+
40+
@Override
41+
public String get() {
42+
long value = Math.abs(theTwister.nextLong());
43+
value %= length;
44+
value += min;
45+
return String.valueOf(value);
46+
}
47+
48+
public String toString() {
49+
return getClass().getSimpleName() + ":" + min + ":" + max;
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dml:
2+
- name: read-tenfields-random
3+
cql: |
4+
select * from <<KEYSPACE>>.<<TABLE>>_tenfields
5+
where key=?
6+
bindings:
7+
key: RandomStringRangeGenerator:1:50000000
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
dml:
2+
- name: read-tenfields-random
3+
cql: |
4+
select * from <<KEYSPACE>>.<<TABLE>>_tenfields
5+
where key='?'
6+
bindings:
7+
key: CycleNumberStringGenerator
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
ddl:
2+
- name: create-keyspace
3+
cql: |
4+
create keyspace if not exists <<KEYSPACE>> WITH replication =
5+
{'class': 'SimpleStrategy', 'replication_factor': <<RF>>} and durable_writes = true;
6+
- name: create-tenfields-table
7+
cql: |
8+
create table if not exists <<KEYSPACE>>.<<TABLE>>_tenfields (
9+
key text primary key,
10+
c0 text,
11+
c1 text,
12+
c2 text,
13+
c3 text,
14+
c4 text,
15+
c5 text,
16+
c6 text,
17+
c7 text,
18+
c8 text,
19+
c9 text,
20+
);
21+
22+
dml:
23+
- name: write-tenfields-random
24+
cql: |
25+
insert into <<KEYSPACE>>.<<TABLE>>_tenfields (key, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9)
26+
values (<<key>>,<<c0>>,<<c1>>,<<c2>>,<<c3>>,<<c4>>,<<c5>>,<<c6>>,<<c7>>,<<c8>>,<<c9>>);
27+
bindings:
28+
key: RandomStringRangeGenerator:1:50000000
29+
c0: LoremExtractGenerator:1000:1000
30+
c1: LoremExtractGenerator:1000:1000
31+
c2: LoremExtractGenerator:1000:1000
32+
c3: LoremExtractGenerator:1000:1000
33+
c4: LoremExtractGenerator:1000:1000
34+
c5: LoremExtractGenerator:1000:1000
35+
c6: LoremExtractGenerator:1000:1000
36+
c7: LoremExtractGenerator:1000:1000
37+
c8: LoremExtractGenerator:1000:1000
38+
c9: LoremExtractGenerator:1000:1000
39+
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
ddl:
2+
- name: create-keyspace
3+
cql: |
4+
create keyspace if not exists <<KEYSPACE>> WITH replication =
5+
{'class': 'SimpleStrategy', 'replication_factor': <<RF>>} and durable_writes = true;
6+
- name: create-tenfields-table
7+
cql: |
8+
create table if not exists <<KEYSPACE>>.<<TABLE>>_tenfields (
9+
key text primary key,
10+
c0 text,
11+
c1 text,
12+
c2 text,
13+
c3 text,
14+
c4 text,
15+
c5 text,
16+
c6 text,
17+
c7 text,
18+
c8 text,
19+
c9 text,
20+
);
21+
22+
dml:
23+
- name: write-tenfields-seq
24+
cql: |
25+
insert into <<KEYSPACE>>.<<TABLE>>_tenfields (key, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9)
26+
values (<<key>>,<<c0>>,<<c1>>,<<c2>>,<<c3>>,<<c4>>,<<c5>>,<<c6>>,<<c7>>,<<c8>>,<<c9>>);
27+
bindings:
28+
key: CycleNumberStringGenerator
29+
c0: LoremExtractGenerator:1000:1000
30+
c1: LoremExtractGenerator:1000:1000
31+
c2: LoremExtractGenerator:1000:1000
32+
c3: LoremExtractGenerator:1000:1000
33+
c4: LoremExtractGenerator:1000:1000
34+
c5: LoremExtractGenerator:1000:1000
35+
c6: LoremExtractGenerator:1000:1000
36+
c7: LoremExtractGenerator:1000:1000
37+
c8: LoremExtractGenerator:1000:1000
38+
c9: LoremExtractGenerator:1000:1000
39+
40+

0 commit comments

Comments
 (0)