Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DATAKV-102 - Add possibility to iterate over available keys. #10

Open
wants to merge 2 commits into
base: 2.7.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>org.springframework.data</groupId>
<artifactId>spring-data-keyvalue</artifactId>
<version>0.1.0.BUILD-SNAPSHOT</version>
<version>0.1.0.DATAKV-102-SNAPSHOT</version>

<name>Spring Data KeyValue</name>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,21 @@ public interface KeyValueAdapter extends DisposableBean {
Iterable<?> getAllOf(Serializable keyspace);

/**
* Returns a {@link KeyValueIterator} that iterates over all entries.
* Returns a {@link KeyValueIterator} that iterates over all entries.
*
* @param keyspace
* @param keyspace must not be {@literal null}.
* @return
*/
KeyValueIterator<? extends Serializable, ?> entries(Serializable keyspace);

/**
* Returns all keys available in {@literal keyspace}.
*
* @param keyspace must not be {@literal null}.
* @return empty {@link Iterable} if no keys available or keyspace unknown.
*/
Iterable<? extends Serializable> keys(Serializable keyspace);

/**
* Remove all objects of given type.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public boolean contains(Serializable id, Serializable keyspace) {
return get(id, keyspace) != null;
}


/* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#count(java.io.Serializable)
*/
Expand Down Expand Up @@ -153,6 +152,15 @@ public Collection<?> getAllOf(Serializable keyspace) {
return new ForwardingKeyValueIterator<Serializable, Object>(getKeySpaceMap(keyspace).entrySet().iterator());
}

/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#keys(java.io.Serializable)
*/
@Override
public Iterable<Serializable> keys(Serializable keyspace) {
return getKeySpaceMap(keyspace).keySet();
}

/*
* (non-Javadoc)
* @see org.springframework.data.keyvalue.core.KeyValueAdapter#deleteAllOf(java.io.Serializable)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.data.map;

import static org.hamcrest.collection.IsEmptyIterable.*;
import static org.hamcrest.collection.IsIterableContainingInAnyOrder.*;
import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsEqual.*;
Expand All @@ -24,6 +25,8 @@

import java.io.Serializable;

import org.hamcrest.collection.IsIterableContainingInAnyOrder;
import org.hamcrest.collection.IsIterableWithSize;
import org.junit.Before;
import org.junit.Test;
import org.springframework.data.keyvalue.core.KeyValueIterator;
Expand Down Expand Up @@ -193,7 +196,7 @@ public void deleteShouldReturnDeletedObject() {
* @see DATAKV-99
*/
@Test
public void scanShouldIterateOverAvailableEntries() {
public void entriesShouldIterateOverAvailableEntries() {

adapter.put("1", object1, COLLECTION_1);
adapter.put("2", object2, COLLECTION_1);
Expand All @@ -209,15 +212,15 @@ public void scanShouldIterateOverAvailableEntries() {
* @see DATAKV-99
*/
@Test
public void scanShouldReturnEmptyIteratorWhenNoElementsAvailable() {
public void entriesShouldReturnEmptyIteratorWhenNoElementsAvailable() {
assertThat(adapter.entries(COLLECTION_1).hasNext(), is(false));
}

/**
* @see DATAKV-99
*/
@Test
public void scanDoesNotMixResultsFromMultipleKeyspaces() {
public void entriesShouldNotMixResultsFromMultipleKeyspaces() {

adapter.put("1", object1, COLLECTION_1);
adapter.put("2", object2, COLLECTION_2);
Expand All @@ -228,6 +231,40 @@ public void scanDoesNotMixResultsFromMultipleKeyspaces() {
assertThat(iterator.hasNext(), is(false));
}

/**
* @see DATAKV-102
*/
@Test
public void keysShouldReturnAvailableKeys() {

adapter.put("1", object1, COLLECTION_1);
adapter.put("2", object2, COLLECTION_1);

Iterable<Serializable> iterable = adapter.keys(COLLECTION_1);

assertThat(iterable, IsIterableContainingInAnyOrder.<Serializable> containsInAnyOrder("1", "2"));
}

/**
* @see DATAKV-102
*/
@Test
public void keyShouldReturnEmptyIterableWhenNoElementsAvailable() {
assertThat(adapter.keys(COLLECTION_1), emptyIterable());
}

/**
* @see DATAKV-102
*/
@Test
public void keysShouldNotMixResultsFromMultipleKeyspaces() {

adapter.put("1", object1, COLLECTION_1);
adapter.put("2", object2, COLLECTION_2);

assertThat(adapter.keys(COLLECTION_1), IsIterableWithSize.<Serializable> iterableWithSize(1));
}

static class SimpleObject {

protected String stringValue;
Expand Down