Commit b61237c7 authored by lichenchong's avatar lichenchong
Browse files

Kinetic Simulator:

Update getKeyRange behavior with the same start key and end key:
If key exists in simulator/drive, 
start key equals end key, start key inclusive, end key inclusive,
getKeyRange return startkey.
start key equals end key, start key inclusive, end key exclusive,
getKeyRange return empty list.
start key equals end key, start key exclusive, end key inclusive,
getKeyRange return empty list.
start key equals end key, start key exclusive, end key exclusive,
getKeyRange return empty list.
parent ef5e5f32
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -355,7 +355,12 @@ public class LevelDbStore implements Store<ByteString, ByteString, KVValue> {
        byte[] end = endKey.toByteArray();

        // Short-circuit when the start key comes after the end key.
        if (compare(start, end) >= 0) {
        if (compare(start, end) > 0) {
            return map;
        }

        if ((compare(start, end) == 0)
                && ((startKeyInclusive && endKeyInclusive) == false)) {
            return map;
        }

@@ -424,9 +429,13 @@ public class LevelDbStore implements Store<ByteString, ByteString, KVValue> {
        byte[] start = startKey.toByteArray();
        byte[] end = endKey.toByteArray();


        // Short-circuit when the start key comes after the end key.
        if (compare(start, end) >= 0) {
        if (compare(start, end) > 0) {
            return listOfKVKey;
        }

        if ((compare(start, end) == 0)
                && ((startKeyInclusive && endKeyInclusive) == false)) {
            return listOfKVKey;
        }

+127 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.Arrays;
import java.util.List;
import java.util.logging.Logger;

@@ -38,6 +39,7 @@ import kinetic.client.advanced.AdvancedKineticClient;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.google.common.collect.Lists;
import com.seagate.kinetic.IntegrationTestCase;
import com.seagate.kinetic.IntegrationTestLoggerFactory;
import com.seagate.kinetic.KineticTestRunner;
@@ -1529,6 +1531,131 @@ public class AdvancedAPIBoundaryTest extends IntegrationTestCase {
		logger.info(this.testEndInfo());
	}
	
	/**
	 * Test getKeyRangeReversed API: startKey equals endKey, startKey inclusive and
	 * endKey inclusive, should return endKey.
	 * <p>
	 *
	 * @throws KineticException
	 *             if any internal error occurred.
	 */
	@Test
	public void testGetKeyRangeReversed_StartKeyEqualsEndKey_StartKeyInclusiveEndKeyInclusive()
			throws KineticException {
		List<byte[]> keys = Arrays.asList(toByteArray("00"), toByteArray("01"),
				toByteArray("02"), toByteArray("03"), toByteArray("04"),
				toByteArray("05"), toByteArray("06"), toByteArray("07"),
				toByteArray("08"), toByteArray("09"), toByteArray("10"),
				toByteArray("11"), toByteArray("12"), toByteArray("13"),
				toByteArray("14"));

		for (byte[] key : keys) {
			getClient().putForced(new Entry(key, key));
		}

		List<byte[]> returnedKeys = Lists.newLinkedList(getClient()
				.getKeyRangeReversed(keys.get(0), true, keys.get(0), true,
						keys.size() - 1));

		assertEquals(1, returnedKeys.size());
		assertArrayEquals(keys.get(0), returnedKeys.get(0));

		logger.info(this.testEndInfo());
	}
	
	/**
	 * Test getKeyRangeReversed API: startKey equals endKey, startKey exclusive and
	 * endKey inclusive, should return empty list.
	 * <p>
	 *
	 * @throws KineticException
	 *             if any internal error occurred.
	 */
	@Test
	public void testGetKeyRangeReversed_StartKeyEqualsEndKey_StartKeyExclusiveEndKeyInclusive()
			throws KineticException {
		List<byte[]> keys = Arrays.asList(toByteArray("00"), toByteArray("01"),
				toByteArray("02"), toByteArray("03"), toByteArray("04"),
				toByteArray("05"), toByteArray("06"), toByteArray("07"),
				toByteArray("08"), toByteArray("09"), toByteArray("10"),
				toByteArray("11"), toByteArray("12"), toByteArray("13"),
				toByteArray("14"));

		for (byte[] key : keys) {
			getClient().putForced(new Entry(key, key));
		}

		List<byte[]> returnedKeys = Lists.newLinkedList(getClient()
				.getKeyRangeReversed(keys.get(0), false, keys.get(0), true,
						keys.size() - 1));

		assertEquals(0, returnedKeys.size());

		logger.info(this.testEndInfo());
	}
	
	/**
	 * Test getKeyRangeReversed API: startKey equals endKey, startKey inclusive and
	 * endKey exclusive, should return empty list.
	 * <p>
	 *
	 * @throws KineticException
	 *             if any internal error occurred.
	 */
	@Test
	public void testGetKeyRangeReversed_StartKeyEqualsEndKey_StartKeyinclusiveEndKeyexclusive()
			throws KineticException {
		List<byte[]> keys = Arrays.asList(toByteArray("00"), toByteArray("01"),
				toByteArray("02"), toByteArray("03"), toByteArray("04"),
				toByteArray("05"), toByteArray("06"), toByteArray("07"),
				toByteArray("08"), toByteArray("09"), toByteArray("10"),
				toByteArray("11"), toByteArray("12"), toByteArray("13"),
				toByteArray("14"));

		for (byte[] key : keys) {
			getClient().putForced(new Entry(key, key));
		}

		List<byte[]> returnedKeys = Lists.newLinkedList(getClient()
				.getKeyRangeReversed(keys.get(0), true, keys.get(0), false,
						keys.size() - 1));

		assertEquals(0, returnedKeys.size());

		logger.info(this.testEndInfo());
	}
	
	/**
	 * Test getKeyRangeReversed API: startKey equals endKey, startKey exclusive and
	 * endKey exclusive, should return empty.
	 * <p>
	 *
	 * @throws KineticException
	 *             if any internal error occurred.
	 */
	@Test
	public void testGetKeyRangeReversed_StartKeyEqualsEndKey_StartKeyexclusiveEndKeyexclusive()
			throws KineticException {
		List<byte[]> keys = Arrays.asList(toByteArray("00"), toByteArray("01"),
				toByteArray("02"), toByteArray("03"), toByteArray("04"),
				toByteArray("05"), toByteArray("06"), toByteArray("07"),
				toByteArray("08"), toByteArray("09"), toByteArray("10"),
				toByteArray("11"), toByteArray("12"), toByteArray("13"),
				toByteArray("14"));

		for (byte[] key : keys) {
			getClient().putForced(new Entry(key, key));
		}

		List<byte[]> returnedKeys = Lists.newLinkedList(getClient()
				.getKeyRangeReversed(keys.get(0), false, keys.get(0), false,
						keys.size() - 1));

		assertEquals(0, returnedKeys.size());

		logger.info(this.testEndInfo());
	}

	/**
	 * GetKeyRangeReversed, no data is stored in simulator/drive, the result of
	 * key list should be empty.
+125 −0
Original line number Diff line number Diff line
@@ -2148,6 +2148,131 @@ public class KineticBoundaryTest extends IntegrationTestCase {
        logger.info(this.testEndInfo());
    }
    
	/**
	 * Test getKeyRange API: startKey equals endKey, startKey inclusive and
	 * endKey inclusive, should return startKey.
	 * <p>
	 *
	 * @throws KineticException
	 *             if any internal error occurred.
	 */
	@Test
	public void testGetKeyRange_StartKeyEqualsEndKey_StartKeyInclusiveEndKeyInclusive()
			throws KineticException {
		List<byte[]> keys = Arrays.asList(toByteArray("00"), toByteArray("01"),
				toByteArray("02"), toByteArray("03"), toByteArray("04"),
				toByteArray("05"), toByteArray("06"), toByteArray("07"),
				toByteArray("08"), toByteArray("09"), toByteArray("10"),
				toByteArray("11"), toByteArray("12"), toByteArray("13"),
				toByteArray("14"));

		for (byte[] key : keys) {
			getClient().putForced(new Entry(key, key));
		}

		List<byte[]> returnedKeys = Lists.newLinkedList(getClient()
				.getKeyRange(keys.get(0), true, keys.get(0), true,
						keys.size() - 1));

		assertEquals(1, returnedKeys.size());
		assertArrayEquals(keys.get(0), returnedKeys.get(0));

		logger.info(this.testEndInfo());
	}
	
	/**
	 * Test getKeyRange API: startKey equals endKey, startKey exclusive and
	 * endKey inclusive, should return empty list.
	 * <p>
	 *
	 * @throws KineticException
	 *             if any internal error occurred.
	 */
	@Test
	public void testGetKeyRange_StartKeyEqualsEndKey_StartKeyExclusiveEndKeyInclusive()
			throws KineticException {
		List<byte[]> keys = Arrays.asList(toByteArray("00"), toByteArray("01"),
				toByteArray("02"), toByteArray("03"), toByteArray("04"),
				toByteArray("05"), toByteArray("06"), toByteArray("07"),
				toByteArray("08"), toByteArray("09"), toByteArray("10"),
				toByteArray("11"), toByteArray("12"), toByteArray("13"),
				toByteArray("14"));

		for (byte[] key : keys) {
			getClient().putForced(new Entry(key, key));
		}

		List<byte[]> returnedKeys = Lists.newLinkedList(getClient()
				.getKeyRange(keys.get(0), false, keys.get(0), true,
						keys.size() - 1));

		assertEquals(0, returnedKeys.size());

		logger.info(this.testEndInfo());
	}
	
	/**
	 * Test getKeyRange API: startKey equals endKey, startKey inclusive and
	 * endKey exclusive, should return empty list.
	 * <p>
	 *
	 * @throws KineticException
	 *             if any internal error occurred.
	 */
	@Test
	public void testGetKeyRange_StartKeyEqualsEndKey_StartKeyinclusiveEndKeyexclusive()
			throws KineticException {
		List<byte[]> keys = Arrays.asList(toByteArray("00"), toByteArray("01"),
				toByteArray("02"), toByteArray("03"), toByteArray("04"),
				toByteArray("05"), toByteArray("06"), toByteArray("07"),
				toByteArray("08"), toByteArray("09"), toByteArray("10"),
				toByteArray("11"), toByteArray("12"), toByteArray("13"),
				toByteArray("14"));

		for (byte[] key : keys) {
			getClient().putForced(new Entry(key, key));
		}

		List<byte[]> returnedKeys = Lists.newLinkedList(getClient()
				.getKeyRange(keys.get(0), true, keys.get(0), false,
						keys.size() - 1));

		assertEquals(0, returnedKeys.size());

		logger.info(this.testEndInfo());
	}
	
	/**
	 * Test getKeyRange API: startKey equals endKey, startKey exclusive and
	 * endKey exclusive, should return empty.
	 * <p>
	 *
	 * @throws KineticException
	 *             if any internal error occurred.
	 */
	@Test
	public void testGetKeyRange_StartKeyEqualsEndKey_StartKeyexclusiveEndKeyexclusive()
			throws KineticException {
		List<byte[]> keys = Arrays.asList(toByteArray("00"), toByteArray("01"),
				toByteArray("02"), toByteArray("03"), toByteArray("04"),
				toByteArray("05"), toByteArray("06"), toByteArray("07"),
				toByteArray("08"), toByteArray("09"), toByteArray("10"),
				toByteArray("11"), toByteArray("12"), toByteArray("13"),
				toByteArray("14"));

		for (byte[] key : keys) {
			getClient().putForced(new Entry(key, key));
		}

		List<byte[]> returnedKeys = Lists.newLinkedList(getClient()
				.getKeyRange(keys.get(0), false, keys.get(0), false,
						keys.size() - 1));

		assertEquals(0, returnedKeys.size());

		logger.info(this.testEndInfo());
	}

    /**
     * GetKeyRange, returns the first contiguous block of keys for which the
     * user has RANGE role. Does not return subsequent keys, even if there is a