Package com.sleepycat.je.util

Examples of com.sleepycat.je.util.StringDbt


        try {
            initEnv(false);
            int count = 0;
            doSimpleCursorPuts();

            StringDbt foundKey = new StringDbt();
            StringDbt foundData = new StringDbt();
            OperationStatus status;
            status = cursor.getLast(foundKey, foundData, LockMode.DEFAULT);

            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals("quux", foundKey.getString());
            assertEquals("seven", foundData.getString());

            status = cursor.getNext(foundKey, foundData, LockMode.DEFAULT);
            assertEquals(OperationStatus.NOTFOUND, status);

            status = cursor.getPrev(foundKey, foundData, LockMode.DEFAULT);

            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals("mumble", foundKey.getString());
            assertEquals("eight", foundData.getString());
        } catch (Throwable t) {
            t.printStackTrace();
            throw t;
        }
    }
View Full Code Here


                fail("didn't catch DatabaseException for twice closed cursor");
            } catch (DatabaseException DBE) {
            }
            try {
                cursor.put
                    (new StringDbt("bogus"), new StringDbt("thingy"));
                fail("didn't catch DatabaseException for re-use of cursor");
            } catch (DatabaseException DBE) {
            }
        } catch (Throwable t) {
            t.printStackTrace();
View Full Code Here

    private void treeSplittingWithDeletedIdKeyWorker()
  throws Throwable {

  initEnv(false);
  StringDbt data = new StringDbt("data");

  Cursor cursor = exampleDb.openCursor(null, null);
  cursor.put(new StringDbt("AGPFX"), data);
  cursor.put(new StringDbt("AHHHH"), data);
  cursor.put(new StringDbt("AIIII"), data);
  cursor.put(new StringDbt("AAAAA"), data);
  cursor.put(new StringDbt("AABBB"), data);
  cursor.put(new StringDbt("AACCC"), data);
  cursor.close();
  exampleDb.delete(null, new StringDbt("AGPFX"));
  exampleEnv.compress();
  cursor = exampleDb.openCursor(null, null);
  cursor.put(new StringDbt("AAAAB"), data);
  cursor.put(new StringDbt("AAAAC"), data);
  cursor.close();
  validateDatabase();
    }
View Full Code Here

        Map expectedMap = new HashMap();
        doLargePut(expectedMap, nKeys, nDupsPerKey, true);
        Long lastNum = fileManager.getLastFileNum();

        /* Read the data back. */
        StringDbt foundKey = new StringDbt();
        StringDbt foundData = new StringDbt();

        Cursor cursor = exampleDb.openCursor(null, null);

        while (cursor.getNext(foundKey, foundData, LockMode.DEFAULT) ==
               OperationStatus.SUCCESS) {
View Full Code Here

                expectedMap.put(keyString, dataVals);
            }
            for (int j = 0; j < nDupsPerKey; j++) {
                String dataString = Integer.toString(j);
                exampleDb.put(txn,
                              new StringDbt(keyString),
                              new StringDbt(dataString));
                dataVals.add(dataString);
            }
        }
        if (commit) {
            txn.commit();
View Full Code Here

                            boolean commit)
        throws DatabaseException {

        Transaction txn = exampleEnv.beginTransaction(null, null);

        StringDbt foundKey = new StringDbt();
        StringDbt foundData = new StringDbt();

        Cursor cursor = exampleDb.openCursor(txn, null);
        OperationStatus status = cursor.getFirst(foundKey, foundData,
                                                 LockMode.DEFAULT);

        boolean toggle = true;
        while (status == OperationStatus.SUCCESS) {
            if (toggle) {

                String foundKeyString = foundKey.getString();
                String foundDataString = foundData.getString();
                int newValue = Integer.parseInt(foundDataString) + increment;
                String newDataString = Integer.toString(newValue);

                /* If committing, adjust the expected map. */
                if (commit) {
               
                    Set dataVals = (Set) expectedMap.get(foundKeyString);
                    if (dataVals == null) {
                        fail("Couldn't find " +
                             foundKeyString + "/" + foundDataString);
                    } else if (dataVals.contains(foundDataString)) {
                        dataVals.remove(foundDataString);
                        dataVals.add(newDataString);
                    } else {
                        fail("Couldn't find " +
                             foundKeyString + "/" + foundDataString);
                    }
                }
                assertEquals(OperationStatus.SUCCESS,
                             cursor.delete());
                assertEquals(OperationStatus.SUCCESS,
                             cursor.put(foundKey,
          new StringDbt(newDataString)));
                toggle = false;
            } else {
                toggle = true;
            }

View Full Code Here

                            boolean commit)
        throws DatabaseException {

        Transaction txn = exampleEnv.beginTransaction(null, null);

        StringDbt foundKey = new StringDbt();
        StringDbt foundData = new StringDbt();

        Cursor cursor = exampleDb.openCursor(txn, null);
        OperationStatus status = cursor.getFirst(foundKey, foundData,
                                                 LockMode.DEFAULT);

        boolean toggle = true;
        while (status == OperationStatus.SUCCESS) {
            if (toggle) {

                String foundKeyString = foundKey.getString();
                String foundDataString = foundData.getString();

                /* If committing, adjust the expected map */
                if (commit) {
               
                    Set dataVals = (Set) expectedMap.get(foundKeyString);
View Full Code Here

     * Check what's in the database against what's in the expected map.
     */
    private void checkData(Map expectedMap)
        throws DatabaseException {

        StringDbt foundKey = new StringDbt();
        StringDbt foundData = new StringDbt();
        Cursor cursor = exampleDb.openCursor(null, null);
        OperationStatus status = cursor.getFirst(foundKey, foundData,
                                                 LockMode.DEFAULT);

        /*
         * Make a copy of expectedMap so that we're free to delete out
         * of the set of expected results when we verify.
         * Also make a set of counts for each key value, to test count.
         */

        Map checkMap = new HashMap();
        Map countMap = new HashMap();
        Iterator iter = expectedMap.entrySet().iterator();
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            Set copySet = new HashSet();
            copySet.addAll((Set) entry.getValue());
            checkMap.put(entry.getKey(), copySet);
            countMap.put(entry.getKey(), new Integer(copySet.size()));
        }    

        while (status == OperationStatus.SUCCESS) {
            String foundKeyString = foundKey.getString();
            String foundDataString = foundData.getString();

            /* Check that the current value is in the check values map */
            Set dataVals = (Set) checkMap.get(foundKeyString);
            if (dataVals == null) {
                fail("Couldn't find " +
View Full Code Here

     */
    private void verify(Hashtable expectedData, boolean doDelete)
  throws DatabaseException {

        Iterator iter = expectedData.entrySet().iterator();
        StringDbt testKey = new StringDbt();
        StringDbt testData = new StringDbt();

        // Iterate over the expected values.
        while (iter.hasNext()) {
            Map.Entry entry = (Map.Entry) iter.next();
            testKey.setString((String) entry.getKey());

            // search for the expected values using SET.
            OperationStatus status = cursor2.getSearchKey(testKey, testData,
                LockMode.DEFAULT);
            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals((String) entry.getValue(), testData.getString());
            assertEquals((String) entry.getKey(), testKey.getString());

            // check that getCurrent returns the same thing.
            status = cursor2.getCurrent(testKey, testData, LockMode.DEFAULT);
            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals((String) entry.getValue(), testData.getString());
            assertEquals((String) entry.getKey(), testKey.getString());

      if (doDelete) {
    // Delete the entry and make sure that getSearchKey doesn't
    // return it again.
    status = cursor2.delete();
    assertEquals(OperationStatus.SUCCESS, status);

    // search for the expected values using SET.
    status =
        cursor2.getSearchKey(testKey, testData, LockMode.DEFAULT);
    assertEquals(OperationStatus.NOTFOUND, status);

    // search for the expected values using SET_BOTH.
    status =
        cursor2.getSearchBoth(testKey, testData, LockMode.DEFAULT);
    assertEquals(OperationStatus.NOTFOUND, status);

    // search for the expected values using SET_RANGE - should
    // give 0 except if this is the last key in the tree, in which
    // case DB_NOTFOUND.  It should never be DB_KEYEMPTY.
    // XXX: It would be nice to be definite about the expected
    // status, but to do that we have to know whether this is the
    // highest key in the set, which we don't currently track.
    status = cursor2.getSearchKeyRange
        (testKey, testData, LockMode.DEFAULT);
    assertTrue(status == OperationStatus.SUCCESS ||
         status == OperationStatus.NOTFOUND);
      } else {
    // search for the expected values using SET_BOTH.
    status =
        cursor2.getSearchBoth(testKey, testData, LockMode.DEFAULT);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals((String) entry.getValue(), testData.getString());
    assertEquals((String) entry.getKey(), testKey.getString());

    // check that getCurrent returns the same thing.
    status =
        cursor2.getCurrent(testKey, testData, LockMode.DEFAULT);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals((String) entry.getValue(), testData.getString());
    assertEquals((String) entry.getKey(), testKey.getString());

    // check that SET_RANGE works as expected for exact keys
    status = cursor2.getSearchKeyRange
        (testKey, testData, LockMode.DEFAULT);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals((String) entry.getValue(), testData.getString());
    assertEquals((String) entry.getKey(), testKey.getString());

    // search for the expected values using SET_RANGE.
    byte[] keyBytes = testKey.getData();
    keyBytes[keyBytes.length - 1]--;
    status = cursor2.getSearchKeyRange
        (testKey, testData, LockMode.DEFAULT);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals((String) entry.getValue(), testData.getString());
    assertEquals((String) entry.getKey(), testKey.getString());

    // check that getCurrent returns the same thing.
    status =
        cursor2.getCurrent(testKey, testData, LockMode.DEFAULT);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals((String) entry.getValue(), testData.getString());
    assertEquals((String) entry.getKey(), testKey.getString());
      }
        }
    }
View Full Code Here

    private void verifyDuplicates(Hashtable expectedData)
  throws DatabaseException {

        Enumeration iter = expectedData.keys();
        StringDbt testKey = new StringDbt();
        StringDbt testData = new StringDbt();

        // Iterate over the expected values.
        while (iter.hasMoreElements()) {
      String key = (String) iter.nextElement();
            testKey.setString(key);

            // search for the expected values using SET.
            OperationStatus status = cursor2.getSearchKey(testKey, testData,
                LockMode.DEFAULT);
            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals(key, testKey.getString());
      String dataString = testData.getString();

            // check that getCurrent returns the same thing.
            status = cursor2.getCurrent(testKey, testData, LockMode.DEFAULT);
            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals(dataString, testData.getString());
            assertEquals(key, testKey.getString());

            // search for the expected values using SET_RANGE.
      byte[] keyBytes = testKey.getData();
      keyBytes[keyBytes.length - 1]--;
            status =
    cursor2.getSearchKeyRange(testKey, testData, LockMode.DEFAULT);
            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals(dataString, testData.getString());
            assertEquals(key, testKey.getString());

            // check that getCurrent returns the same thing.
            status = cursor2.getCurrent(testKey, testData, LockMode.DEFAULT);
            assertEquals(OperationStatus.SUCCESS, status);
            assertEquals(dataString, testData.getString());
            assertEquals(key, testKey.getString());

      Hashtable ht = (Hashtable) expectedData.get(key);

      Enumeration iter2 = ht.keys();
      while (iter2.hasMoreElements()) {
    String expectedDataString = (String) iter2.nextElement();
    testData.setString(expectedDataString);

    // search for the expected values using SET_BOTH.
    status =
        cursor2.getSearchBoth(testKey, testData, LockMode.DEFAULT);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(expectedDataString, testData.getString());
    assertEquals(key, testKey.getString());

    // check that getCurrent returns the same thing.
    status =
        cursor2.getCurrent(testKey, testData, LockMode.DEFAULT);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(expectedDataString, testData.getString());
    assertEquals(key, testKey.getString());

    // search for the expected values using SET_RANGE_BOTH.
    byte[] dataBytes = testData.getData();
    dataBytes[dataBytes.length - 1]--;
    status = cursor2.getSearchBothRange(testKey, testData,
                LockMode.DEFAULT);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(key, testKey.getString());
    assertEquals(expectedDataString, testData.getString());

    // check that getCurrent returns the same thing.
    status = cursor2.getCurrent(testKey, testData,
              LockMode.DEFAULT);
    assertEquals(OperationStatus.SUCCESS, status);
    assertEquals(expectedDataString, testData.getString());
    assertEquals(key, testKey.getString());
      }
        }
    }
View Full Code Here

TOP

Related Classes of com.sleepycat.je.util.StringDbt

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.