Skip to content

Commit

Permalink
fix: update delete by id bugs
Browse files Browse the repository at this point in the history
Signed-off-by: Otavio Santana <[email protected]>
  • Loading branch information
otaviojava committed Nov 29, 2023
1 parent d9bec89 commit 277db14
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
4 changes: 2 additions & 2 deletions core/src/main/java/expert/os/harperdb/Template.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public <K, T> boolean deleteAllById(Class<T> type, Iterable<K> ids) {
Objects.requireNonNull(ids, "ids is required");
var keys = StreamSupport.stream(ids.spliterator(), false)
.collect(Collectors.toSet());
var delete = new Delete<>(database, table(type), Collections.singleton(keys));
var delete = new Delete<>(database, table(type), keys);
return server.execute(delete);
}

Expand All @@ -100,7 +100,7 @@ public <K> boolean deleteAllById(String table, Iterable<K> ids) {
Objects.requireNonNull(ids, "ids is required");
var keys = StreamSupport.stream(ids.spliterator(), false)
.collect(Collectors.toSet());
var delete = new Delete<>(database, table, keys, ALL_ATTRIBUTES);
var delete = new Delete<>(database, table, keys);
return server.execute(delete);
}

Expand Down
20 changes: 20 additions & 0 deletions core/src/test/java/expert/os/harperdb/TemplateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,26 @@ void shouldUpdateAnimals(List<Animal> animals){
.map(Animal::id).containsAll(animalsUpdated.stream().map(Animal::id).toList());
}

@ParameterizedTest
@MethodSource("animal")
void shouldDeleteAnimal(Animal animal){
this.template.upsert(animal);
Assertions.assertThat(this.template.findById(animal.id(), Animal.class)).isNotEmpty();
this.template.delete(Animal.class, animal.id());
Assertions.assertThat(this.template.findById(animal.id(), Animal.class)).isEmpty();

}

@ParameterizedTest
@MethodSource("animals")
void shouldDeleteAllAnimals(List<Animal> animals){
this.template.upsert(animals);
var ids = animals.stream().map(Animal::id).toList();
Assertions.assertThat(this.template.findAllById(ids, Animal.class)).isNotEmpty().hasSize(ids.size());
this.template.deleteAllById(Animal.class, ids);
Assertions.assertThat(this.template.findAllById(ids, Animal.class)).isEmpty();
}

static Stream<Arguments> animal(){
return Stream.of(Arguments.of(new Animal(FAKER.idNumber().valid(), FAKER.animal().name())));
}
Expand Down

0 comments on commit 277db14

Please sign in to comment.