Search in sources :

Example 76 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class HBaseClient1 method update.

/**
 * Update a record in the database. Any field/value pairs in the specified
 * values HashMap will be written into the record with the specified record
 * key, overwriting any existing values with the same field name.
 *
 * @param table
 *          The name of the table
 * @param key
 *          The record key of the record to write
 * @param values
 *          A HashMap of field/value pairs to update in the record
 * @return Zero on success, a non-zero error code on error
 */
@Override
public Status update(String table, String key, Map<String, ByteIterator> values) {
    // if this is a "new" table, init HTable object. Else, use existing one
    if (!tableName.equals(table)) {
        currentTable = null;
        try {
            getHTable(table);
            tableName = table;
        } catch (IOException e) {
            System.err.println("Error accessing HBase table: " + e);
            return Status.ERROR;
        }
    }
    if (debug) {
        System.out.println("Setting up put for key: " + key);
    }
    Put p = new Put(Bytes.toBytes(key));
    p.setDurability(durability);
    for (Map.Entry<String, ByteIterator> entry : values.entrySet()) {
        byte[] value = entry.getValue().toArray();
        if (debug) {
            System.out.println("Adding field/value " + entry.getKey() + "/" + Bytes.toStringBinary(value) + " to put request");
        }
        p.addColumn(columnFamilyBytes, Bytes.toBytes(entry.getKey()), value);
    }
    try {
        if (clientSideBuffering) {
            // removed Preconditions.checkNotNull, which throws NPE, in favor of NPE on next line
            bufferedMutator.mutate(p);
        } else {
            currentTable.put(p);
        }
    } catch (IOException e) {
        if (debug) {
            System.err.println("Error doing put: " + e);
        }
        return Status.ERROR;
    } catch (ConcurrentModificationException e) {
        // do nothing for now...hope this is rare
        return Status.ERROR;
    }
    return Status.OK;
}
Also used : ConcurrentModificationException(java.util.ConcurrentModificationException) ByteIterator(site.ycsb.ByteIterator) ByteArrayByteIterator(site.ycsb.ByteArrayByteIterator) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) Put(org.apache.hadoop.hbase.client.Put)

Example 77 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class TestTimeSeriesWorkload method insertWithValidation.

@Test
public void insertWithValidation() throws Exception {
    final Properties p = getUTProperties();
    p.put(CoreWorkload.FIELD_COUNT_PROPERTY, "1");
    p.put(CoreWorkload.DATA_INTEGRITY_PROPERTY, "true");
    p.put(TimeSeriesWorkload.VALUE_TYPE_PROPERTY, "integers");
    final TimeSeriesWorkload wl = getWorkload(p, true);
    final Object threadState = wl.initThread(p, 0, 1);
    final MockDB db = new MockDB();
    for (int i = 0; i < 74; i++) {
        assertTrue(wl.doInsert(db, threadState));
    }
    assertEquals(db.keys.size(), 74);
    assertEquals(db.values.size(), 74);
    long timestamp = 1451606400;
    for (int i = 0; i < db.keys.size(); i++) {
        assertEquals(db.keys.get(i), "AAAA");
        assertEquals(db.values.get(i).get("AA").toString(), "AAAA");
        assertEquals(Utils.bytesToLong(db.values.get(i).get(TimeSeriesWorkload.TIMESTAMP_KEY_PROPERTY_DEFAULT).toArray()), timestamp);
        assertFalse(((NumericByteIterator) db.values.get(i).get(TimeSeriesWorkload.VALUE_KEY_PROPERTY_DEFAULT)).isFloatingPoint());
        // validation check
        final TreeMap<String, String> validationTags = new TreeMap<String, String>();
        for (final Entry<String, ByteIterator> entry : db.values.get(i).entrySet()) {
            if (entry.getKey().equals(TimeSeriesWorkload.VALUE_KEY_PROPERTY_DEFAULT) || entry.getKey().equals(TimeSeriesWorkload.TIMESTAMP_KEY_PROPERTY_DEFAULT)) {
                continue;
            }
            validationTags.put(entry.getKey(), entry.getValue().toString());
        }
        assertEquals(wl.validationFunction(db.keys.get(i), timestamp, validationTags), ((NumericByteIterator) db.values.get(i).get(TimeSeriesWorkload.VALUE_KEY_PROPERTY_DEFAULT)).getLong());
        if (i % 2 == 0) {
            assertEquals(db.values.get(i).get("AB").toString(), "AAAA");
        } else {
            assertEquals(db.values.get(i).get("AB").toString(), "AAAB");
            timestamp += 60;
        }
    }
}
Also used : ByteIterator(site.ycsb.ByteIterator) NumericByteIterator(site.ycsb.NumericByteIterator) StringByteIterator(site.ycsb.StringByteIterator) Properties(java.util.Properties) TreeMap(java.util.TreeMap) Test(org.testng.annotations.Test)

Example 78 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class RestClientTest method read_200.

// Read success.
@Test
public void read_200() {
    HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
    Status status = rc.read(null, VALID_RESOURCE, null, result);
    assertEquals(Status.OK, status);
    assertEquals(result.get(RESPONSE_TAG).toString(), "HTTP GET response to: " + VALID_RESOURCE);
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 79 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class RestClientTest method update_200.

@Test
public void update_200() {
    HashMap<String, ByteIterator> data = new HashMap<String, ByteIterator>();
    data.put(DATA_TAG, new StringByteIterator(INPUT_DATA));
    Status status = rc.update(null, VALID_RESOURCE, data);
    assertEquals(Status.OK, status);
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) StringByteIterator(site.ycsb.StringByteIterator) Test(org.junit.Test)

Example 80 with ByteIterator

use of site.ycsb.ByteIterator in project YCSB by brianfrankcooper.

the class RestClientTest method read_500.

// Server error.
@Test
public void read_500() {
    HashMap<String, ByteIterator> result = new HashMap<String, ByteIterator>();
    Status status = rc.read(null, INVALID_RESOURCE, null, result);
    assertEquals(Status.ERROR, status);
}
Also used : Status(site.ycsb.Status) ByteIterator(site.ycsb.ByteIterator) StringByteIterator(site.ycsb.StringByteIterator) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

ByteIterator (site.ycsb.ByteIterator)131 HashMap (java.util.HashMap)98 StringByteIterator (site.ycsb.StringByteIterator)92 Status (site.ycsb.Status)62 Test (org.junit.Test)53 ByteArrayByteIterator (site.ycsb.ByteArrayByteIterator)34 DBException (site.ycsb.DBException)30 Map (java.util.Map)20 IOException (java.io.IOException)10 Put (org.apache.hadoop.hbase.client.Put)8 ArrayList (java.util.ArrayList)7 Vector (java.util.Vector)7 ByteBuffer (java.nio.ByteBuffer)6 HashSet (java.util.HashSet)6 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 NumericByteIterator (site.ycsb.NumericByteIterator)5 EntityProperty (com.microsoft.azure.storage.table.EntityProperty)4 Properties (java.util.Properties)4 Assume.assumeNoException (org.junit.Assume.assumeNoException)4 DB (site.ycsb.DB)4