diff --git a/asynchbase/src/main/java/com/yahoo/ycsb/db/AsyncHBaseClient.java b/asynchbase/src/main/java/com/yahoo/ycsb/db/AsyncHBaseClient.java index fddd1a7aef3b9be60178d7d36cb1852b547b8086..eecbee36f9e383b1e5826934ed1594dbb73230d9 100644 --- a/asynchbase/src/main/java/com/yahoo/ycsb/db/AsyncHBaseClient.java +++ b/asynchbase/src/main/java/com/yahoo/ycsb/db/AsyncHBaseClient.java @@ -39,6 +39,9 @@ import com.yahoo.ycsb.ByteIterator; import com.yahoo.ycsb.DBException; import com.yahoo.ycsb.Status; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY_DEFAULT; + /** * Alternative Java client for Apache HBase. * @@ -140,7 +143,7 @@ public class AsyncHBaseClient extends com.yahoo.ycsb.DB { // Terminate right now if table does not exist, since the client // will not propagate this error upstream once the workload // starts. - String table = com.yahoo.ycsb.workloads.CoreWorkload.table; + String table = getProperties().getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT); try { client.ensureTableExists(table).join(joinTimeout); } catch (InterruptedException e1) { diff --git a/asynchbase/src/test/java/com/yahoo/ycsb/db/AsyncHBaseTest.java b/asynchbase/src/test/java/com/yahoo/ycsb/db/AsyncHBaseTest.java index 29a09a79677c7c42dd1b0a9177d9e24f0bbd0b53..536cec7cb8561d009caebd372cb257c0b1f6f4fa 100644 --- a/asynchbase/src/test/java/com/yahoo/ycsb/db/AsyncHBaseTest.java +++ b/asynchbase/src/test/java/com/yahoo/ycsb/db/AsyncHBaseTest.java @@ -16,6 +16,8 @@ */ package com.yahoo.ycsb.db; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY_DEFAULT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -25,7 +27,6 @@ import static org.junit.Assume.assumeTrue; import com.yahoo.ycsb.ByteIterator; import com.yahoo.ycsb.Status; import com.yahoo.ycsb.StringByteIterator; -import com.yahoo.ycsb.db.AsyncHBaseClient; import com.yahoo.ycsb.measurements.Measurements; import com.yahoo.ycsb.workloads.CoreWorkload; @@ -61,6 +62,7 @@ public class AsyncHBaseTest { private static HBaseTestingUtility testingUtil; private AsyncHBaseClient client; private Table table = null; + private String tableName; private static boolean isWindows() { final String os = System.getProperty("os.name"); @@ -105,7 +107,8 @@ public class AsyncHBaseTest { final CoreWorkload workload = new CoreWorkload(); workload.init(p); - table = testingUtil.createTable(TableName.valueOf(CoreWorkload.table), Bytes.toBytes(COLUMN_FAMILY)); + tableName = p.getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT); + table = testingUtil.createTable(TableName.valueOf(tableName), Bytes.toBytes(COLUMN_FAMILY)); final String zkQuorum = "127.0.0.1:" + testingUtil.getZkCluster().getClientPort(); p.setProperty("hbase.zookeeper.quorum", zkQuorum); @@ -117,7 +120,7 @@ public class AsyncHBaseTest { @After public void tearDown() throws Exception { table.close(); - testingUtil.deleteTable(CoreWorkload.table); + testingUtil.deleteTable(tableName); } @Test @@ -131,7 +134,7 @@ public class AsyncHBaseTest { table.put(p); final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>(); - final Status status = client.read(CoreWorkload.table, rowKey, null, result); + final Status status = client.read(tableName, rowKey, null, result); assertEquals(Status.OK, status); assertEquals(2, result.size()); assertEquals("value1", result.get("column1").toString()); @@ -141,7 +144,7 @@ public class AsyncHBaseTest { @Test public void testReadMissingRow() throws Exception { final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>(); - final Status status = client.read(CoreWorkload.table, "Missing row", null, result); + final Status status = client.read(tableName, "Missing row", null, result); assertEquals(Status.NOT_FOUND, status); assertEquals(0, result.size()); } @@ -167,7 +170,7 @@ public class AsyncHBaseTest { new Vector<HashMap<String, ByteIterator>>(); // Scan 5 records, skipping the first - client.scan(CoreWorkload.table, "00001", 5, null, result); + client.scan(tableName, "00001", 5, null, result); assertEquals(5, result.size()); for(int i = 0; i < 5; i++) { @@ -187,7 +190,7 @@ public class AsyncHBaseTest { final HashMap<String, String> input = new HashMap<String, String>(); input.put("column1", "value1"); input.put("column2", "value2"); - final Status status = client.insert(CoreWorkload.table, key, StringByteIterator.getByteIteratorMap(input)); + final Status status = client.insert(tableName, key, StringByteIterator.getByteIteratorMap(input)); assertEquals(Status.OK, status); // Verify result diff --git a/cassandra/src/test/java/com/yahoo/ycsb/db/CassandraCQLClientTest.java b/cassandra/src/test/java/com/yahoo/ycsb/db/CassandraCQLClientTest.java index 870d5a7df830c8d249e42d7ff0f4b76bed549bea..82c22983767e43ccab97b3d315ee4b3a0f7d21d4 100644 --- a/cassandra/src/test/java/com/yahoo/ycsb/db/CassandraCQLClientTest.java +++ b/cassandra/src/test/java/com/yahoo/ycsb/db/CassandraCQLClientTest.java @@ -126,7 +126,7 @@ public class CassandraCQLClientTest { insertRow(); final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>(); - final Status status = client.read(CoreWorkload.table, DEFAULT_ROW_KEY, null, result); + final Status status = client.read(TABLE, DEFAULT_ROW_KEY, null, result); assertThat(status, is(Status.OK)); assertThat(result.entrySet(), hasSize(11)); assertThat(result, hasEntry("field2", null)); @@ -147,7 +147,7 @@ public class CassandraCQLClientTest { insertRow(); final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>(); final Set<String> fields = Sets.newHashSet("field1"); - final Status status = client.read(CoreWorkload.table, DEFAULT_ROW_KEY, fields, result); + final Status status = client.read(TABLE, DEFAULT_ROW_KEY, fields, result); assertThat(status, is(Status.OK)); assertThat(result.entrySet(), hasSize(1)); final Map<String, String> strResult = StringByteIterator.getStringMap(result); diff --git a/checkstyle.xml b/checkstyle.xml index af0065d07693733fdfdf5a8f5524816f8a8d2f6a..6041ba4b71462808903a4225feccddce53c34afe 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -171,7 +171,9 @@ LICENSE file. <module name="FinalClass"/> <module name="HideUtilityClassConstructor"/> <module name="InterfaceIsType"/> - <module name="VisibilityModifier"/> + <module name="VisibilityModifier"> + <property name="protectedAllowed" value="true"/> + </module> <!-- Miscellaneous other checks. --> diff --git a/core/src/main/java/com/yahoo/ycsb/workloads/CoreWorkload.java b/core/src/main/java/com/yahoo/ycsb/workloads/CoreWorkload.java index 422dc05475d1534a717ab63077c7a6525ce52c5d..3e4adfaa5fcb3551f6f3168f17674cdfe2671c29 100644 --- a/core/src/main/java/com/yahoo/ycsb/workloads/CoreWorkload.java +++ b/core/src/main/java/com/yahoo/ycsb/workloads/CoreWorkload.java @@ -1,12 +1,12 @@ /** * Copyright (c) 2010 Yahoo! Inc., Copyright (c) 2016 YCSB contributors. All rights reserved. - * + * <p> * Licensed 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 - * + * <p> * http://www.apache.org/licenses/LICENSE-2.0 - * + * <p> * 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 @@ -17,39 +17,18 @@ package com.yahoo.ycsb.workloads; -import java.util.Properties; - import com.yahoo.ycsb.*; -import com.yahoo.ycsb.generator.AcknowledgedCounterGenerator; -import com.yahoo.ycsb.generator.ConstantIntegerGenerator; -import com.yahoo.ycsb.generator.CounterGenerator; -import com.yahoo.ycsb.generator.DiscreteGenerator; -import com.yahoo.ycsb.generator.ExponentialGenerator; -import com.yahoo.ycsb.generator.HistogramGenerator; -import com.yahoo.ycsb.generator.HotspotIntegerGenerator; -import com.yahoo.ycsb.generator.NumberGenerator; -import com.yahoo.ycsb.generator.ScrambledZipfianGenerator; -import com.yahoo.ycsb.generator.SequentialGenerator; -import com.yahoo.ycsb.generator.SkewedLatestGenerator; -import com.yahoo.ycsb.generator.UniformIntegerGenerator; -import com.yahoo.ycsb.generator.ZipfianGenerator; +import com.yahoo.ycsb.generator.*; import com.yahoo.ycsb.measurements.Measurements; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Vector; - +import java.util.*; /** * The core benchmark scenario. Represents a set of clients doing simple CRUD operations. The * relative proportion of different kinds of operations, and other properties of the workload, * are controlled by parameters specified at runtime. - * + * <p> * Properties to control the client: * <UL> * <LI><b>fieldcount</b>: the number of fields in a record (default: 10) @@ -75,7 +54,7 @@ import java.util.Vector; * <LI><b>zeropadding</b>: for generating a record sequence compatible with string sort order by * 0 padding the record number. Controls the number of 0s to use for padding. (default: 1) * For example for row 5, with zeropadding=1 you get 'user5' key and with zeropading=8 you get - * 'user00000005' key. In order to see its impact, zeropadding needs to be bigger than number of + * 'user00000005' key. In order to see its impact, zeropadding needs to be bigger than number of * digits in the record number. * <LI><b>insertorder</b>: should records be inserted in order by key ("ordered"), or in hashed * order ("hashed") (default: hashed) @@ -92,8 +71,7 @@ public class CoreWorkload extends Workload { */ public static final String TABLENAME_PROPERTY_DEFAULT = "usertable"; - public static String table; - + protected String table; /** * The name of the property for the number of fields in a record. @@ -105,14 +83,14 @@ public class CoreWorkload extends Workload { */ public static final String FIELD_COUNT_PROPERTY_DEFAULT = "10"; - int fieldcount; + protected int fieldcount; private List<String> fieldnames; /** * The name of the property for the field length distribution. Options are "uniform", "zipfian" * (favouring short records), "constant", and "histogram". - * + * <p> * If "uniform", "zipfian" or "constant", the maximum field length will be that specified by the * fieldlength property. If "histogram", then the histogram will be read from the filename * specified in the "fieldlengthhistogram" property. @@ -149,7 +127,7 @@ public class CoreWorkload extends Workload { * Generator object that produces field lengths. The value of this depends on the properties that * start with "FIELD_LENGTH_". */ - NumberGenerator fieldlengthgenerator; + protected NumberGenerator fieldlengthgenerator; /** * The name of the property for deciding whether to read one field (false) or all fields (true) of @@ -162,7 +140,7 @@ public class CoreWorkload extends Workload { */ public static final String READ_ALL_FIELDS_PROPERTY_DEFAULT = "true"; - boolean readallfields; + protected boolean readallfields; /** * The name of the property for deciding whether to write one field (false) or all fields (true) @@ -175,8 +153,7 @@ public class CoreWorkload extends Workload { */ public static final String WRITE_ALL_FIELDS_PROPERTY_DEFAULT = "false"; - boolean writeallfields; - + protected boolean writeallfields; /** * The name of the property for deciding whether to check all returned @@ -256,7 +233,7 @@ public class CoreWorkload extends Workload { */ public static final String REQUEST_DISTRIBUTION_PROPERTY_DEFAULT = "uniform"; - /** + /** * The name of the property for adding zero padding to record numbers in order to match * string sort order. Controls the number of 0s to left pad with. */ @@ -267,7 +244,7 @@ public class CoreWorkload extends Workload { */ public static final String ZERO_PADDING_PROPERTY_DEFAULT = "1"; - + /** * The name of the property for the max scan length (number of records). */ @@ -331,27 +308,19 @@ public class CoreWorkload extends Workload { public static final String INSERTION_RETRY_INTERVAL = "core_workload_insertion_retry_interval"; public static final String INSERTION_RETRY_INTERVAL_DEFAULT = "3"; - NumberGenerator keysequence; - - DiscreteGenerator operationchooser; - - NumberGenerator keychooser; - - NumberGenerator fieldchooser; - - AcknowledgedCounterGenerator transactioninsertkeysequence; + protected NumberGenerator keysequence; + protected DiscreteGenerator operationchooser; + protected NumberGenerator keychooser; + protected NumberGenerator fieldchooser; + protected AcknowledgedCounterGenerator transactioninsertkeysequence; + protected NumberGenerator scanlength; + protected boolean orderedinserts; + protected int recordcount; + protected int zeropadding; + protected int insertionRetryLimit; + protected int insertionRetryInterval; - NumberGenerator scanlength; - - boolean orderedinserts; - - int recordcount; - int zeropadding; - - int insertionRetryLimit; - int insertionRetryInterval; - - private Measurements _measurements = Measurements.getMeasurements(); + private Measurements measurements = Measurements.getMeasurements(); protected static NumberGenerator getFieldLengthGenerator(Properties p) throws WorkloadException { NumberGenerator fieldlengthgenerator; @@ -391,12 +360,12 @@ public class CoreWorkload extends Workload { fieldcount = Integer.parseInt(p.getProperty(FIELD_COUNT_PROPERTY, FIELD_COUNT_PROPERTY_DEFAULT)); - fieldnames = new ArrayList<String>(); + fieldnames = new ArrayList<>(); for (int i = 0; i < fieldcount; i++) { fieldnames.add("field" + i); } fieldlengthgenerator = CoreWorkload.getFieldLengthGenerator(p); - + recordcount = Integer.parseInt(p.getProperty(Client.RECORD_COUNT_PROPERTY, Client.DEFAULT_RECORD_COUNT)); if (recordcount == 0) { @@ -432,8 +401,8 @@ public class CoreWorkload extends Workload { // Confirm that fieldlengthgenerator returns a constant if data // integrity check requested. if (dataintegrity && !(p.getProperty( - FIELD_LENGTH_DISTRIBUTION_PROPERTY, - FIELD_LENGTH_DISTRIBUTION_PROPERTY_DEFAULT)).equals("constant")) { + FIELD_LENGTH_DISTRIBUTION_PROPERTY, + FIELD_LENGTH_DISTRIBUTION_PROPERTY_DEFAULT)).equals("constant")) { System.err.println("Must have constant field size to check data integrity."); System.exit(-1); } @@ -460,7 +429,7 @@ public class CoreWorkload extends Workload { keychooser = new UniformIntegerGenerator(insertstart, insertstart + insertcount - 1); } else if (requestdistrib.compareTo("sequential") == 0) { keychooser = new SequentialGenerator(insertstart, insertstart + insertcount - 1); - }else if (requestdistrib.compareTo("zipfian") == 0) { + } else if (requestdistrib.compareTo("zipfian") == 0) { // it does this by generating a random "next key" in part by taking the modulus over the // number of keys. // If the number of keys changes, this would shift the modulus, and we don't want that to @@ -506,14 +475,14 @@ public class CoreWorkload extends Workload { INSERTION_RETRY_INTERVAL, INSERTION_RETRY_INTERVAL_DEFAULT)); } - public String buildKeyName(long keynum) { + protected String buildKeyName(long keynum) { if (!orderedinserts) { keynum = Utils.hash(keynum); } String value = Long.toString(keynum); int fill = zeropadding - value.length(); String prekey = "user"; - for(int i=0; i<fill; i++) { + for (int i = 0; i < fill; i++) { prekey += '0'; } return prekey + value; @@ -523,7 +492,7 @@ public class CoreWorkload extends Workload { * Builds a value for a randomly chosen field. */ private HashMap<String, ByteIterator> buildSingleValue(String key) { - HashMap<String, ByteIterator> value = new HashMap<String, ByteIterator>(); + HashMap<String, ByteIterator> value = new HashMap<>(); String fieldkey = fieldnames.get(fieldchooser.nextValue().intValue()); ByteIterator data; @@ -542,7 +511,7 @@ public class CoreWorkload extends Workload { * Builds values for all fields. */ private HashMap<String, ByteIterator> buildValues(String key) { - HashMap<String, ByteIterator> values = new HashMap<String, ByteIterator>(); + HashMap<String, ByteIterator> values = new HashMap<>(); for (String fieldkey : fieldnames) { ByteIterator data; @@ -626,7 +595,12 @@ public class CoreWorkload extends Workload { */ @Override public boolean doTransaction(DB db, Object threadstate) { - switch (operationchooser.nextString()) { + String operation = operationchooser.nextString(); + if(operation == null) { + return false; + } + + switch (operation) { case "READ": doTransactionRead(db); break; @@ -641,7 +615,7 @@ public class CoreWorkload extends Workload { break; default: doTransactionReadModifyWrite(db); - } + } return true; } @@ -668,11 +642,11 @@ public class CoreWorkload extends Workload { verifyStatus = Status.ERROR; } long endTime = System.nanoTime(); - _measurements.measure("VERIFY", (int) (endTime - startTime) / 1000); - _measurements.reportStatus("VERIFY", verifyStatus); + measurements.measure("VERIFY", (int) (endTime - startTime) / 1000); + measurements.reportStatus("VERIFY", verifyStatus); } - int nextKeynum() { + protected int nextKeynum() { int keynum; if (keychooser instanceof ExponentialGenerator) { do { @@ -712,7 +686,7 @@ public class CoreWorkload extends Workload { verifyRow(keyname, cells); } } - + public void doTransactionReadModifyWrite(DB db) { // choose a random key int keynum = nextKeynum(); @@ -744,7 +718,7 @@ public class CoreWorkload extends Workload { HashMap<String, ByteIterator> cells = new HashMap<String, ByteIterator>(); - long ist = _measurements.getIntendedtartTimeNs(); + long ist = measurements.getIntendedtartTimeNs(); long st = System.nanoTime(); db.read(table, keyname, fields, cells); @@ -756,8 +730,8 @@ public class CoreWorkload extends Workload { verifyRow(keyname, cells); } - _measurements.measure("READ-MODIFY-WRITE", (int) ((en - st) / 1000)); - _measurements.measureIntended("READ-MODIFY-WRITE", (int) ((en - ist) / 1000)); + measurements.measure("READ-MODIFY-WRITE", (int) ((en - st) / 1000)); + measurements.measureIntended("READ-MODIFY-WRITE", (int) ((en - ist) / 1000)); } public void doTransactionScan(DB db) { @@ -820,11 +794,12 @@ public class CoreWorkload extends Workload { * Weights/proportions are read from the properties list and defaults are used * when values are not configured. * Current operations are "READ", "UPDATE", "INSERT", "SCAN" and "READMODIFYWRITE". + * * @param p The properties list to pull weights from. * @return A generator that can be used to determine the next operation to perform. * @throws IllegalArgumentException if the properties object was null. */ - public static DiscreteGenerator createOperationGenerator(final Properties p) { + protected static DiscreteGenerator createOperationGenerator(final Properties p) { if (p == null) { throw new IllegalArgumentException("Properties object cannot be null"); } @@ -838,7 +813,7 @@ public class CoreWorkload extends Workload { p.getProperty(SCAN_PROPORTION_PROPERTY, SCAN_PROPORTION_PROPERTY_DEFAULT)); final double readmodifywriteproportion = Double.parseDouble(p.getProperty( READMODIFYWRITE_PROPORTION_PROPERTY, READMODIFYWRITE_PROPORTION_PROPERTY_DEFAULT)); - + final DiscreteGenerator operationchooser = new DiscreteGenerator(); if (readproportion > 0) { operationchooser.addValue(readproportion, "READ"); diff --git a/core/src/main/java/com/yahoo/ycsb/workloads/RestWorkload.java b/core/src/main/java/com/yahoo/ycsb/workloads/RestWorkload.java index b407753f6eeb83a2dc46f2444445af4f21a00b74..6eb0a96edab28b49da7fff5db63385fa7c84f2ef 100644 --- a/core/src/main/java/com/yahoo/ycsb/workloads/RestWorkload.java +++ b/core/src/main/java/com/yahoo/ycsb/workloads/RestWorkload.java @@ -107,6 +107,8 @@ public class RestWorkload extends CoreWorkload { private NumberGenerator insertKeyChooser; private NumberGenerator deleteKeyChooser; private NumberGenerator updateKeyChooser; + private NumberGenerator fieldlengthgenerator; + private DiscreteGenerator operationchooser; @Override public void init(Properties p) throws WorkloadException { diff --git a/hbase098/src/main/java/com/yahoo/ycsb/db/HBaseClient.java b/hbase098/src/main/java/com/yahoo/ycsb/db/HBaseClient.java index 9b097b37b4a39df69c4955bd9fbca36d09db124c..f2bcfede8a4b5234eebd159e5946e1ce9de5bd41 100644 --- a/hbase098/src/main/java/com/yahoo/ycsb/db/HBaseClient.java +++ b/hbase098/src/main/java/com/yahoo/ycsb/db/HBaseClient.java @@ -26,14 +26,12 @@ import com.yahoo.ycsb.measurements.Measurements; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.HBaseConfiguration; -import org.apache.hadoop.hbase.HTableDescriptor; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.HConnectionManager; import org.apache.hadoop.hbase.client.HConnection; import org.apache.hadoop.hbase.client.HTableInterface; import org.apache.hadoop.hbase.client.Delete; import org.apache.hadoop.hbase.client.Get; -import org.apache.hadoop.hbase.client.HTable; import org.apache.hadoop.hbase.client.Put; import org.apache.hadoop.hbase.client.Result; import org.apache.hadoop.hbase.client.ResultScanner; @@ -52,6 +50,9 @@ import java.util.Set; import java.util.Vector; import java.util.concurrent.atomic.AtomicInteger; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY_DEFAULT; + /** * HBase client for YCSB framework */ @@ -135,7 +136,7 @@ public class HBaseClient extends com.yahoo.ycsb.DB // Terminate right now if table does not exist, since the client // will not propagate this error upstream once the workload // starts. - String table = com.yahoo.ycsb.workloads.CoreWorkload.table; + String table = getProperties().getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT); try { HTableInterface ht = _hConn.getTable(table); diff --git a/hbase10/src/main/java/com/yahoo/ycsb/db/HBaseClient10.java b/hbase10/src/main/java/com/yahoo/ycsb/db/HBaseClient10.java index da72f4f86c6d0101defde14c7548c49ea887f213..2ef4defaccf8e55125ee69b15c10d8f7a514895d 100644 --- a/hbase10/src/main/java/com/yahoo/ycsb/db/HBaseClient10.java +++ b/hbase10/src/main/java/com/yahoo/ycsb/db/HBaseClient10.java @@ -53,6 +53,9 @@ import java.util.Set; import java.util.Vector; import java.util.concurrent.atomic.AtomicInteger; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY_DEFAULT; + /** * HBase 1.0 client for YCSB framework. * @@ -173,7 +176,7 @@ public class HBaseClient10 extends com.yahoo.ycsb.DB { // Terminate right now if table does not exist, since the client // will not propagate this error upstream once the workload // starts. - String table = com.yahoo.ycsb.workloads.CoreWorkload.table; + String table = getProperties().getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT); try { final TableName tName = TableName.valueOf(table); synchronized (CONNECTION_LOCK) { diff --git a/hbase10/src/test/java/com/yahoo/ycsb/db/HBaseClient10Test.java b/hbase10/src/test/java/com/yahoo/ycsb/db/HBaseClient10Test.java index 631e822710d70d2227ab327e9eb0a97b5817b8e4..f77595ba83ba846e5676c03fe601ec8750a98111 100644 --- a/hbase10/src/test/java/com/yahoo/ycsb/db/HBaseClient10Test.java +++ b/hbase10/src/test/java/com/yahoo/ycsb/db/HBaseClient10Test.java @@ -15,6 +15,8 @@ package com.yahoo.ycsb.db; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY_DEFAULT; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; @@ -59,6 +61,7 @@ public class HBaseClient10Test { private static HBaseTestingUtility testingUtil; private HBaseClient10 client; private Table table = null; + private String tableName; private static boolean isWindows() { final String os = System.getProperty("os.name"); @@ -106,7 +109,8 @@ public class HBaseClient10Test { final CoreWorkload workload = new CoreWorkload(); workload.init(p); - table = testingUtil.createTable(TableName.valueOf(CoreWorkload.table), Bytes.toBytes(COLUMN_FAMILY)); + tableName = p.getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT); + table = testingUtil.createTable(TableName.valueOf(tableName), Bytes.toBytes(COLUMN_FAMILY)); client.setProperties(p); client.init(); @@ -115,7 +119,7 @@ public class HBaseClient10Test { @After public void tearDown() throws Exception { table.close(); - testingUtil.deleteTable(CoreWorkload.table); + testingUtil.deleteTable(tableName); } @Test @@ -129,7 +133,7 @@ public class HBaseClient10Test { table.put(p); final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>(); - final Status status = client.read(CoreWorkload.table, rowKey, null, result); + final Status status = client.read(tableName, rowKey, null, result); assertEquals(Status.OK, status); assertEquals(2, result.size()); assertEquals("value1", result.get("column1").toString()); @@ -139,7 +143,7 @@ public class HBaseClient10Test { @Test public void testReadMissingRow() throws Exception { final HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>(); - final Status status = client.read(CoreWorkload.table, "Missing row", null, result); + final Status status = client.read(tableName, "Missing row", null, result); assertEquals(Status.NOT_FOUND, status); assertEquals(0, result.size()); } @@ -165,7 +169,7 @@ public class HBaseClient10Test { new Vector<HashMap<String, ByteIterator>>(); // Scan 5 records, skipping the first - client.scan(CoreWorkload.table, "00001", 5, null, result); + client.scan(tableName, "00001", 5, null, result); assertEquals(5, result.size()); for(int i = 0; i < 5; i++) { @@ -185,7 +189,7 @@ public class HBaseClient10Test { final HashMap<String, String> input = new HashMap<String, String>(); input.put("column1", "value1"); input.put("column2", "value2"); - final Status status = client.insert(CoreWorkload.table, key, StringByteIterator.getByteIteratorMap(input)); + final Status status = client.insert(tableName, key, StringByteIterator.getByteIteratorMap(input)); assertEquals(Status.OK, status); // Verify result diff --git a/kudu/src/main/java/com/yahoo/ycsb/db/KuduYCSBClient.java b/kudu/src/main/java/com/yahoo/ycsb/db/KuduYCSBClient.java index 2d68a178c0f64de0b9962288a3bab12411516f97..b7ae0e2b0e82de0a983a0ef6d0cd8850d812cf5f 100644 --- a/kudu/src/main/java/com/yahoo/ycsb/db/KuduYCSBClient.java +++ b/kudu/src/main/java/com/yahoo/ycsb/db/KuduYCSBClient.java @@ -37,6 +37,8 @@ import java.util.Properties; import java.util.Set; import java.util.Vector; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY; +import static com.yahoo.ycsb.workloads.CoreWorkload.TABLENAME_PROPERTY_DEFAULT; import static org.apache.kudu.Type.STRING; import static org.apache.kudu.client.KuduPredicate.ComparisonOp.EQUAL; import static org.apache.kudu.client.KuduPredicate.ComparisonOp.GREATER_EQUAL; @@ -80,7 +82,7 @@ public class KuduYCSBClient extends com.yahoo.ycsb.DB { @Override public void init() throws DBException { - String tableName = CoreWorkload.table; + String tableName = getProperties().getProperty(TABLENAME_PROPERTY, TABLENAME_PROPERTY_DEFAULT); initClient(tableName, getProperties()); this.session = client.newSession(); if (getProperties().getProperty(SYNC_OPS_OPT) != null