-
Notifications
You must be signed in to change notification settings - Fork 9
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
Test/stable db tests #194
base: develop
Are you sure you want to change the base?
Test/stable db tests #194
Changes from 9 commits
0882595
ab80471
173a95c
01478a7
0f07f8d
2b935f6
042ee95
aac0059
01e17cb
4fdb06d
23994a6
29245fb
355bc81
b2a8186
b575797
1cb4db6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,20 @@ | ||
dependencies { | ||
api project(':types') | ||
api project(':crypto') | ||
api(project(':types')) { | ||
exclude group: 'junit' | ||
} | ||
|
||
api(project(':crypto')) { | ||
exclude group: 'junit' | ||
} | ||
|
||
api "org.rocksdb:rocksdbjni" | ||
api "com.googlecode.concurrent-locks:concurrent-locks" | ||
|
||
testImplementation 'org.junit.jupiter:junit-jupiter:5.5.1' | ||
|
||
test { | ||
useJUnitPlatform { | ||
excludeTags 'FIX' | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package org.ethereum.beacon.db; | ||
|
||
import org.ethereum.beacon.db.source.DataSource; | ||
import org.ethereum.beacon.db.source.impl.HashMapDataSource; | ||
import org.junit.jupiter.api.Tag; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import tech.pegasys.artemis.util.bytes.BytesValue; | ||
|
||
import java.nio.file.InvalidPathException; | ||
import java.util.stream.Stream; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
|
||
class DatabaseTest { | ||
|
||
@Tag("FIX") | ||
@ParameterizedTest | ||
@MethodSource("invalidArgumentsProvider") | ||
void testInvalidCreation(String path, long bufferLimitsInBytes) { | ||
assertThatThrownBy(() -> Database.rocksDB(path, bufferLimitsInBytes)) | ||
.isInstanceOf(InvalidPathException.class); | ||
} | ||
|
||
@Test | ||
void testInvalidCreationWithNull() { | ||
assertThatThrownBy(() -> Database.rocksDB(null, 0)).isInstanceOf(NullPointerException.class); | ||
} | ||
|
||
private static Stream<Arguments> invalidArgumentsProvider() { | ||
return Stream.of(Arguments.of("null", 0), Arguments.of("", 0), Arguments.of("0123", 0)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("validArgumentsProvider") | ||
void testValidCreation(String path, long bufferLimitsInBytes) { | ||
final Database database = Database.rocksDB(path, bufferLimitsInBytes); | ||
assertThat(database).isNotNull(); | ||
} | ||
|
||
private static Stream<Arguments> validArgumentsProvider() { | ||
return Stream.of( | ||
Arguments.of("/tmp", 0), | ||
Arguments.of("/tmp", Long.MAX_VALUE), | ||
Arguments.of("/tmp", Long.MIN_VALUE)); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This likely won't work on windows. |
||
|
||
private static final String TEST_STORAGE_NAME = "TEST_STORAGE_NAME"; | ||
|
||
private boolean committed; | ||
private boolean closed; | ||
private String storageName; | ||
|
||
@Test | ||
void testDatabaseCommitCloseCreateStorage() { | ||
final DataSource<BytesValue, BytesValue> dataSource = new HashMapDataSource<>(); | ||
committed = false; | ||
closed = false; | ||
storageName = null; | ||
|
||
final Database db = | ||
new Database() { | ||
@Override | ||
public DataSource<BytesValue, BytesValue> createStorage(String name) { | ||
storageName = name; | ||
return dataSource; | ||
} | ||
|
||
@Override | ||
public void commit() { | ||
committed = true; | ||
} | ||
|
||
@Override | ||
public void close() { | ||
closed = true; | ||
} | ||
}; | ||
|
||
final DataSource<BytesValue, BytesValue> storage = db.createStorage(TEST_STORAGE_NAME); | ||
assertThat(storage).isEqualTo(dataSource); | ||
assertThat(storageName).isEqualTo(TEST_STORAGE_NAME); | ||
|
||
assertThat(committed).isFalse(); | ||
db.commit(); | ||
assertThat(committed).isTrue(); | ||
|
||
assertThat(closed).isFalse(); | ||
db.close(); | ||
assertThat(closed).isTrue(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test tests your implementation of Database interface. Useless again. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless isNotNull test again.