Skip to content

Commit

Permalink
Add deleteByKey tests to Geode adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
asereda-gs committed Oct 15, 2019
1 parent e437847 commit 744bde1
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion criteria/geode/src/org/immutables/criteria/geode/Geodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.immutables.criteria.geode;

import com.google.common.base.Preconditions;
import org.apache.geode.cache.Region;
import org.immutables.criteria.Criteria;
import org.immutables.criteria.backend.ProjectedTuple;
import org.immutables.criteria.expression.Call;
Expand Down Expand Up @@ -87,7 +88,7 @@ private static Object convert(Object value, Type destinationType) {

/**
* Geode (currently) doesn't support delete by query syntax ({@code DELETE ... WHERE ...}) and elements have to be
* removed explicitly by key ({@link Map#remove(Object)} API)
* removed explicitly by key (using {@link Map#remove(Object)} or {@link Region#removeAll} API)
*
* <p>Tries to detect if current criteria is based only on keys and extract them from expression (if it is only
* expression based on keys).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
import org.immutables.criteria.backend.Backend;
import org.immutables.criteria.backend.WithSessionCallback;
import org.immutables.criteria.personmodel.AbstractPersonTest;
import org.immutables.criteria.personmodel.Person;
import org.immutables.criteria.personmodel.PersonGenerator;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.util.EnumSet;
Expand Down Expand Up @@ -52,4 +55,28 @@ public void nested() {
// nested doesn't work yet in Geode. Need custom PDX serializer
}

@Test
void deleteByKey() {
PersonGenerator generator = new PersonGenerator();
repository().insert(generator.next().withId("id1"));
repository().insert(generator.next().withId("id2"));
repository().insert(generator.next().withId("id3"));

repository().delete(person.id.in("bad1", "bad2"));

// nothing was deleted (bad ids)
check(repository().findAll()).toList(Person::id).hasContentInAnyOrder("id1", "id2", "id3");

repository().delete(person.id.is("id1"));
check(repository().findAll()).toList(Person::id).hasContentInAnyOrder("id2", "id3");

repository().delete(person.id.in("id1", "id1"));
check(repository().findAll()).toList(Person::id).hasContentInAnyOrder("id2", "id3");

repository().delete(person.id.in("id2", "id2", "id1"));
check(repository().findAll()).toList(Person::id).hasContentInAnyOrder("id3");

repository().delete(person.id.in("id2", "id2", "id1", "id3"));
check(repository().findAll()).toList(Person::id).isEmpty();
}
}

0 comments on commit 744bde1

Please sign in to comment.