-
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
Open
eustimenko
wants to merge
16
commits into
develop
Choose a base branch
from
test/stable-db-tests
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Test/stable db tests #194
Changes from 1 commit
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
0882595
test: add junit5 into gradle
eustimenko ab80471
test: replace junit4 with junit5 in java code
eustimenko 173a95c
test: db/core/src/test/java/org/ethereum/beacon/db/DatabaseTest
eustimenko 01478a7
test: db/core/src/test/java/org/ethereum/beacon/db/DatabaseTest
eustimenko 0f07f8d
test: add junit4 dependency into test module
eustimenko 2b935f6
test: fix junit 4/5 dependencies
eustimenko 042ee95
Community tests updated to be in line with develop
zilm13 aac0059
test: reformat code
eustimenko 01e17cb
test: update subproject
eustimenko 4fdb06d
test: fix DatabaseTest after code review
eustimenko 23994a6
test: fix DatabaseTest after code review
eustimenko 29245fb
test: delete directories
eustimenko 355bc81
test: add relative directories
eustimenko b2a8186
test: add additional test for Database
eustimenko b575797
test: correct InMemoryDatabaseTest
eustimenko 1cb4db6
test: add Database tests
eustimenko File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test: fix DatabaseTest after code review
- Loading branch information
commit 4fdb06d52171510294be9332259e0e52742ad5f2
There are no files selected for viewing
78 changes: 19 additions & 59 deletions
78
db/core/src/test/java/org/ethereum/beacon/db/DatabaseTest.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 |
---|---|---|
@@ -1,95 +1,55 @@ | ||
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.ethereum.beacon.db.rocksdb.RocksDbSource; | ||
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 org.rocksdb.RocksDBException; | ||
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); | ||
void testInvalidCreation() { | ||
final EngineDrivenDatabase database = (EngineDrivenDatabase) Database.rocksDB("", 0); | ||
final RocksDbSource upstream = (RocksDbSource) database.getWriteBuffer().getUpstream(); | ||
assertThatThrownBy(upstream::open) | ||
.isInstanceOf(RuntimeException.class) | ||
.hasCauseExactlyInstanceOf(RocksDBException.class); | ||
} | ||
|
||
private static Stream<Arguments> invalidArgumentsProvider() { | ||
return Stream.of(Arguments.of("", 0), Arguments.of("0123", 0)); | ||
} | ||
|
||
@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(); | ||
final EngineDrivenDatabase database = (EngineDrivenDatabase) Database.rocksDB(path, bufferLimitsInBytes); | ||
final RocksDbSource upstream = (RocksDbSource) database.getWriteBuffer().getUpstream(); | ||
upstream.open(); | ||
upstream.put(BytesValue.of(123), BytesValue.of(1, 2, 3)); | ||
assertThat(database.getWriteBuffer().get(BytesValue.of(123))).isPresent().hasValue(BytesValue.of(1, 2, 3)); | ||
upstream.close(); | ||
} | ||
|
||
private static Stream<Arguments> validArgumentsProvider() { | ||
return Stream.of( | ||
Arguments.of("", 0), | ||
Arguments.of("/tmp", 0), | ||
Arguments.of("/tmp", Long.MAX_VALUE), | ||
Arguments.of("/tmp", Long.MIN_VALUE)); | ||
} | ||
|
||
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(); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This likely won't work on windows.
Additionaly, RocksDB creates files. It's a good idea to clean up, i.e. remove the directories, created by RocksDB.