You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by be...@apache.org on 2015/03/10 18:12:43 UTC
cassandra git commit: include missing files
Repository: cassandra
Updated Branches:
refs/heads/trunk a0586f692 -> b7563f823
include missing files
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/b7563f82
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/b7563f82
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/b7563f82
Branch: refs/heads/trunk
Commit: b7563f823ed5cacd553721016ab4609e85685afd
Parents: a0586f6
Author: Benedict Elliott Smith <be...@apache.org>
Authored: Tue Mar 10 17:12:31 2015 +0000
Committer: Benedict Elliott Smith <be...@apache.org>
Committed: Tue Mar 10 17:12:31 2015 +0000
----------------------------------------------------------------------
.../apache/cassandra/io/util/MemoryTest.java | 75 ++++++++++
.../cassandra/stress/util/TimingIntervals.java | 139 +++++++++++++++++++
2 files changed, 214 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b7563f82/test/unit/org/apache/cassandra/io/util/MemoryTest.java
----------------------------------------------------------------------
diff --git a/test/unit/org/apache/cassandra/io/util/MemoryTest.java b/test/unit/org/apache/cassandra/io/util/MemoryTest.java
new file mode 100644
index 0000000..7e37265
--- /dev/null
+++ b/test/unit/org/apache/cassandra/io/util/MemoryTest.java
@@ -0,0 +1,75 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.cassandra.io.util;
+
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
+import java.util.concurrent.ThreadLocalRandom;
+
+import org.junit.Test;
+
+import junit.framework.Assert;
+import org.apache.cassandra.utils.memory.MemoryUtil;
+
+public class MemoryTest
+{
+
+ @Test
+ public void testByteBuffers()
+ {
+ byte[] bytes = new byte[1000];
+ ThreadLocalRandom.current().nextBytes(bytes);
+ final Memory memory = Memory.allocate(bytes.length);
+ memory.setBytes(0, bytes, 0, bytes.length);
+ ByteBuffer canon = ByteBuffer.wrap(bytes).order(ByteOrder.nativeOrder());
+ test(canon, memory);
+ memory.setBytes(0, new byte[1000], 0, 1000);
+ memory.setBytes(0, canon.duplicate());
+ test(canon, memory);
+ }
+
+ private static void test(ByteBuffer canon, Memory memory)
+ {
+ ByteBuffer hollow = MemoryUtil.getHollowDirectByteBuffer();
+ test(canon, hollow, memory, 0, 1000);
+ test(canon, hollow, memory, 33, 100);
+ test(canon, hollow, memory, 77, 77);
+ test(canon, hollow, memory, 903, 96);
+ }
+
+ private static void test(ByteBuffer canon, ByteBuffer hollow, Memory memory, int offset, int length)
+ {
+ canon = canon.duplicate();
+ canon.position(offset).limit(offset + length);
+ canon = canon.slice().order(ByteOrder.nativeOrder());
+ test(canon, memory.asByteBuffer(offset, length));
+ memory.setByteBuffer(hollow, offset, length);
+ test(canon, hollow);
+ }
+
+ private static void test(ByteBuffer canon, ByteBuffer test)
+ {
+ Assert.assertEquals(canon, test);
+ for (int i = 0 ; i <= canon.limit() - 4 ; i += 4)
+ Assert.assertEquals(canon.getInt(i), test.getInt(i));
+ for (int i = 0 ; i <= canon.limit() - 8 ; i += 8)
+ Assert.assertEquals(canon.getLong(i), test.getLong(i));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/cassandra/blob/b7563f82/tools/stress/src/org/apache/cassandra/stress/util/TimingIntervals.java
----------------------------------------------------------------------
diff --git a/tools/stress/src/org/apache/cassandra/stress/util/TimingIntervals.java b/tools/stress/src/org/apache/cassandra/stress/util/TimingIntervals.java
new file mode 100644
index 0000000..ab89d07
--- /dev/null
+++ b/tools/stress/src/org/apache/cassandra/stress/util/TimingIntervals.java
@@ -0,0 +1,139 @@
+package org.apache.cassandra.stress.util;
+
+import java.util.Arrays;
+import java.util.Map;
+import java.util.TreeMap;
+
+public class TimingIntervals
+{
+ final Map<String, TimingInterval> intervals;
+ TimingIntervals(Iterable<String> opTypes)
+ {
+ long now = System.nanoTime();
+ intervals = new TreeMap<>();
+ for (String opType : opTypes)
+ intervals.put(opType, new TimingInterval(now));
+ }
+
+ TimingIntervals(Map<String, TimingInterval> intervals)
+ {
+ this.intervals = intervals;
+ }
+
+ public TimingIntervals merge(TimingIntervals with, int maxSamples, long start)
+ {
+ assert intervals.size() == with.intervals.size();
+ TreeMap<String, TimingInterval> ret = new TreeMap<>();
+
+ for (String opType : intervals.keySet())
+ {
+ assert with.intervals.containsKey(opType);
+ ret.put(opType, TimingInterval.merge(Arrays.asList(intervals.get(opType), with.intervals.get(opType)), maxSamples, start));
+ }
+
+ return new TimingIntervals(ret);
+ }
+
+ public TimingInterval get(String opType)
+ {
+ return intervals.get(opType);
+ }
+
+ public TimingInterval combine(int maxSamples)
+ {
+ long start = Long.MAX_VALUE;
+ for (TimingInterval ti : intervals.values())
+ start = Math.min(start, ti.startNanos());
+
+ return TimingInterval.merge(intervals.values(), maxSamples, start);
+ }
+
+ public String str(TimingInterval.TimingParameter value)
+ {
+ return str(value, Float.NaN);
+ }
+
+ public String str(TimingInterval.TimingParameter value, float rank)
+ {
+ StringBuilder sb = new StringBuilder("[");
+
+ for (Map.Entry<String, TimingInterval> entry : intervals.entrySet())
+ {
+ sb.append(entry.getKey());
+ sb.append(":");
+ sb.append(entry.getValue().getStringValue(value, rank));
+ sb.append(", ");
+ }
+
+ sb.setLength(sb.length()-2);
+ sb.append("]");
+
+ return sb.toString();
+ }
+
+ public String opRates()
+ {
+ return str(TimingInterval.TimingParameter.OPRATE);
+ }
+ public String partitionRates()
+ {
+ return str(TimingInterval.TimingParameter.PARTITIONRATE);
+ }
+ public String rowRates()
+ {
+ return str(TimingInterval.TimingParameter.ROWRATE);
+ }
+ public String meanLatencies()
+ {
+ return str(TimingInterval.TimingParameter.MEANLATENCY);
+ }
+ public String maxLatencies()
+ {
+ return str(TimingInterval.TimingParameter.MAXLATENCY);
+ }
+ public String medianLatencies()
+ {
+ return str(TimingInterval.TimingParameter.MEDIANLATENCY);
+ }
+ public String rankLatencies(float rank)
+ {
+ return str(TimingInterval.TimingParameter.MEDIANLATENCY, rank);
+ }
+ public String errorCounts()
+ {
+ return str(TimingInterval.TimingParameter.ERRORCOUNT);
+ }
+ public String partitionCounts()
+ {
+ return str(TimingInterval.TimingParameter.PARTITIONCOUNT);
+ }
+
+ public long opRate()
+ {
+ long v = 0;
+ for (TimingInterval interval : intervals.values())
+ v += interval.opRate();
+ return v;
+ }
+
+ public long startNanos()
+ {
+ long start = Long.MAX_VALUE;
+ for (TimingInterval interval : intervals.values())
+ start = Math.min(start, interval.startNanos());
+ return start;
+ }
+
+ public long endNanos()
+ {
+ long end = Long.MIN_VALUE;
+ for (TimingInterval interval : intervals.values())
+ end = Math.max(end, interval.startNanos());
+ return end;
+ }
+
+ public Map<String, TimingInterval> intervals()
+ {
+ return intervals;
+ }
+}