-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: bootstrap TaskRepository #1626
- Loading branch information
Showing
5 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
datashare-db/src/main/java/org/icij/datashare/db/JooqTaskRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package org.icij.datashare.db; | ||
|
||
import org.icij.datashare.asynctasks.Task; | ||
import org.icij.datashare.asynctasks.TaskRepository; | ||
import org.jooq.SQLDialect; | ||
|
||
import javax.sql.DataSource; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
public class JooqTaskRepository implements TaskRepository { | ||
private final DataSource connectionProvider; | ||
private final SQLDialect dialect; | ||
|
||
JooqTaskRepository(final DataSource connectionProvider, final SQLDialect dialect) { | ||
this.connectionProvider = connectionProvider; | ||
this.dialect = dialect; | ||
} | ||
|
||
@Override | ||
public int size() { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean isEmpty() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean containsKey(Object o) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean containsValue(Object o) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Task<?> get(Object o) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Task<?> put(String s, Task<?> task) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public Task<?> remove(Object o) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void putAll(Map<? extends String, ? extends Task<?>> map) { | ||
|
||
} | ||
|
||
@Override | ||
public void clear() { | ||
|
||
} | ||
|
||
@Override | ||
public Set<String> keySet() { | ||
return Set.of(); | ||
} | ||
|
||
@Override | ||
public Collection<Task<?>> values() { | ||
return List.of(); | ||
} | ||
|
||
@Override | ||
public Set<Entry<String, Task<?>>> entrySet() { | ||
return Set.of(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
datashare-db/src/test/java/org/icij/datashare/db/JooqTaskRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package org.icij.datashare.db; | ||
|
||
import org.icij.datashare.asynctasks.Task; | ||
import org.icij.datashare.test.DatashareTimeRule; | ||
import org.icij.datashare.user.User; | ||
import org.junit.Ignore; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
|
||
import static java.util.Arrays.asList; | ||
import static org.fest.assertions.Assertions.assertThat; | ||
|
||
@RunWith(Parameterized.class) | ||
public class JooqTaskRepositoryTest { | ||
@Rule | ||
public DatashareTimeRule time = new DatashareTimeRule("2021-06-30T12:13:14Z"); | ||
@Rule | ||
public DbSetupRule dbRule; | ||
private final JooqTaskRepository repository; | ||
|
||
@Ignore | ||
@Test | ||
public void test_get_put() { | ||
Task<Object> foo = new Task<>("foo", User.local(), Map.of()); | ||
repository.put("foo", foo); | ||
assertThat(repository.get("foo")).isNotSameAs(foo); // not same instance | ||
assertThat(repository.get("foo")).isEqualTo(foo); // but equals as defined by Task | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static Collection<Object[]> dataSources() { | ||
return asList(new Object[][]{ | ||
{new DbSetupRule("jdbc:sqlite:file:memorydb.db?mode=memory&cache=shared")}, | ||
{new DbSetupRule("jdbc:postgresql://postgres/dstest?user=dstest&password=test")} | ||
}); | ||
} | ||
|
||
|
||
|
||
public JooqTaskRepositoryTest(DbSetupRule rule) { | ||
dbRule = rule; | ||
repository = rule.createTaskRepository(); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
datashare-tasks/src/main/java/org/icij/datashare/asynctasks/TaskRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.icij.datashare.asynctasks; | ||
|
||
import java.util.Map; | ||
|
||
public interface TaskRepository extends Map<String, Task<?>> { | ||
} |