Skip to content

Commit

Permalink
Small fixes in homework 7
Browse files Browse the repository at this point in the history
  • Loading branch information
arhostcode committed Nov 23, 2023
1 parent 37b2bc9 commit c48ba11
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import lombok.SneakyThrows;
import org.jetbrains.annotations.Nullable;

public class CachingPersonDatabase extends AbstractPersonDatabase {
public class SynchronizedCachingPersonDatabase extends AbstractPersonDatabase {

@SneakyThrows
@Override
Expand Down
6 changes: 4 additions & 2 deletions src/test/java/edu/hw7/task3/PersonDatabaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.util.List;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import lombok.SneakyThrows;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -19,9 +20,9 @@ public void lockDatabase_shouldReturnCorrectPerson_whenPersonAdded() {
}

@Test
@DisplayName("Тестирование CachingPersonDatabase")
@DisplayName("Тестирование SynchronizedCachingPersonDatabase")
public void synchronizedDatabase_shouldReturnCorrectPerson_whenPersonAdded() {
PersonDatabase personDatabase = new CachingPersonDatabase() {
PersonDatabase personDatabase = new SynchronizedCachingPersonDatabase() {
@SneakyThrows
@Override
public synchronized void add(Person person) {
Expand All @@ -42,6 +43,7 @@ private static void testDatabase(PersonDatabase personDatabase) {
Future<List<Person>> futureByName = executorService.submit(() -> personDatabase.findByName("Ivan"));
Future<List<Person>> futureByAddress = executorService.submit(() -> personDatabase.findByAddress("Moscow"));
executorService.shutdown();
executorService.awaitTermination(Integer.MAX_VALUE, TimeUnit.SECONDS);
assertAll(
() -> Assertions.assertThat(futureByPhone.get()).contains(person),
() -> Assertions.assertThat(futureByName.get()).contains(person),
Expand Down

0 comments on commit c48ba11

Please sign in to comment.