Skip to content
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/db module tests #164

Open
wants to merge 47 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
5e4a41f
InMemoryDatabase: property tests
eustimenko Aug 9, 2019
a8cc578
XorKeyDatabase: property tests
eustimenko Aug 9, 2019
a23e3b1
WritableCacheImpl: property tests
eustimenko Aug 9, 2019
d0d232e
WritableCacheImpl/DelegateDataSourceTest
eustimenko Aug 13, 2019
8545359
HashMapHoleyListTest
eustimenko Aug 13, 2019
1913308
LinkedDataSourceTest
eustimenko Aug 14, 2019
00fd312
DataSourceListTest
eustimenko Aug 14, 2019
a9283d2
Fix after code review
eustimenko Aug 14, 2019
4c0cb48
XorDataSourceTest
eustimenko Aug 14, 2019
045421e
AbstractLinkedDataSourceTest
eustimenko Aug 14, 2019
9384595
HoleyListTest
eustimenko Aug 14, 2019
f6f2b31
Merge branch 'develop' into test/db-module-tests
eustimenko Aug 14, 2019
fcd0997
Remove WriteCacheImplTest
eustimenko Aug 15, 2019
d519fee
Avoid unnecessary merklisation of initial deposits (#171)
mkalinin Aug 16, 2019
9a4aac2
JUnit5 and db tests
eustimenko Aug 26, 2019
b1b898e
SingleValueSourceTest/AutoclosableLockTest
eustimenko Aug 28, 2019
0112d23
Merge branch 'develop' into test/db-module-tests
eustimenko Aug 28, 2019
0739114
CacheSizeEvaluatorImplTest
eustimenko Aug 28, 2019
9ba3288
DatabaseFlusherTest
eustimenko Aug 28, 2019
352f9cb
InstantFlusherTest
eustimenko Aug 28, 2019
7ef7ee2
Refactor tests
eustimenko Aug 28, 2019
7023717
test: add BufferSizeObserverTest. Exclude junit4 from db project depe…
eustimenko Sep 4, 2019
452ffa1
test: add param tests to BufferSizeObserverTest
eustimenko Sep 5, 2019
9d4d65d
test: TransactionalDataSourceTest, WriteBufferTest, HashMapDataSource…
eustimenko Sep 10, 2019
44a569a
test: add parameters into tests
eustimenko Sep 12, 2019
ac23ca6
test: BatchUpdateDataSourceTest/CacheDataSourceTest/CacheSizeEvaluato…
eustimenko Sep 16, 2019
22b2e1e
test: fix after review
eustimenko Sep 16, 2019
9f0ccfc
test: add non-null checking into BufferSizeObserver
eustimenko Sep 16, 2019
e1db551
test: add flush test into BufferSizeObserver
eustimenko Sep 17, 2019
0882595
test: add junit5 into gradle
eustimenko Sep 17, 2019
ab80471
test: replace junit4 with junit5 in java code
eustimenko Sep 17, 2019
173a95c
test: db/core/src/test/java/org/ethereum/beacon/db/DatabaseTest
eustimenko Sep 17, 2019
01478a7
test: db/core/src/test/java/org/ethereum/beacon/db/DatabaseTest
eustimenko Sep 17, 2019
0f07f8d
test: add junit4 dependency into test module
eustimenko Sep 18, 2019
2b935f6
test: fix junit 4/5 dependencies
eustimenko Sep 18, 2019
042ee95
Community tests updated to be in line with develop
zilm13 Sep 18, 2019
aac0059
test: reformat code
eustimenko Sep 18, 2019
01e17cb
test: update subproject
eustimenko Sep 18, 2019
4fdb06d
test: fix DatabaseTest after code review
eustimenko Sep 18, 2019
23994a6
test: fix DatabaseTest after code review
eustimenko Sep 18, 2019
29245fb
test: delete directories
eustimenko Sep 18, 2019
355bc81
test: add relative directories
eustimenko Sep 18, 2019
b2a8186
test: add additional test for Database
eustimenko Sep 19, 2019
faa259a
test: fix after merge
eustimenko Sep 19, 2019
2ebabd0
test: correct InMemoryDatabaseTest
eustimenko Sep 19, 2019
9ffb987
test: correct InMemoryDatabaseTest
eustimenko Sep 19, 2019
93cbead
test: temp commit
eustimenko Sep 19, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions db/core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
dependencies {
api project(':types')

testImplementation 'com.pholser:junit-quickcheck-core:0.7'
testImplementation 'ru.vyarus:generics-resolver:3.0.0'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.ethereum.beacon.db;

import com.pholser.junit.quickcheck.Property;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import org.ethereum.beacon.db.source.impl.HashMapDataSource;
import org.junit.runner.RunWith;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(JUnitQuickcheck.class)
public class InMemoryDatabaseTest {

@Property
public void getBackingDataSource() {
final InMemoryDatabase database = new InMemoryDatabase();
assertThat(database.getBackingDataSource()).isNotNull();
assertThat(database.getBackingDataSource()).isInstanceOf(HashMapDataSource.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.ethereum.beacon.db;

import com.pholser.junit.quickcheck.*;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import org.ethereum.beacon.db.configuration.*;
import org.ethereum.beacon.db.source.DataSource;
import org.ethereum.beacon.db.source.impl.XorDataSource;
import org.junit.runner.RunWith;
import tech.pegasys.artemis.util.bytes.BytesValue;

import java.util.function.Function;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(JUnitQuickcheck.class)
public class XorKeyDatabaseTest {

private final String TEST_STORAGE_NAME = "TEST_STORAGE_NAME";
private final String TEST_ENTITY_KEY = "TEST_ENTITY_KEY";

@Property
public void createStorage(@From(HashMapDatasourceGenerator.class) DataSource<@From(EmptyBytesValueGenerator.class) BytesValue, @From(EmptyBytesValueGenerator.class) BytesValue> backingDataSource,
@From(EmptyFunctionGenerator.class) Function<@From(EmptyBytesValueGenerator.class) BytesValue, @From(EmptyBytesValueGenerator.class) BytesValue> sourceNameHasher) {

final XorKeyDatabase database = new XorKeyDatabase(backingDataSource, sourceNameHasher) {
@Override
public void commit() {
}

@Override
public void close() {
}
};

final DataSource<BytesValue, BytesValue> actual = database.createStorage(TEST_STORAGE_NAME);
assertThat(actual).isNotNull();
assertThat(actual).isInstanceOf(XorDataSource.class);

final BytesValue key = BytesValue.wrap(TEST_ENTITY_KEY.getBytes());
final BytesValue value = BytesValue.EMPTY;
actual.put(key, value);
assertThat(actual.get(key)).isPresent().hasValue(value);
eustimenko marked this conversation as resolved.
Show resolved Hide resolved
}

@Property
public void getBackingDataSource(@From(HashMapDatasourceGenerator.class) DataSource<@From(EmptyBytesValueGenerator.class) BytesValue, @From(EmptyBytesValueGenerator.class) BytesValue> backingDataSource,
@From(EmptyFunctionGenerator.class) Function<@From(EmptyBytesValueGenerator.class) BytesValue, @From(EmptyBytesValueGenerator.class) BytesValue> sourceNameHasher) {

final XorKeyDatabase actual = new XorKeyDatabase(backingDataSource, sourceNameHasher) {
@Override
public void commit() {
}

@Override
public void close() {
}
};

assertThat(actual).isNotNull();
assertThat(actual.getBackingDataSource()).isNotNull();
assertThat(actual.getBackingDataSource()).isEqualTo(backingDataSource);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.ethereum.beacon.db.configuration;

import com.pholser.junit.quickcheck.generator.*;
Copy link
Member

@zilm13 zilm13 Aug 12, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't use wildcard imports

import com.pholser.junit.quickcheck.random.SourceOfRandomness;
import tech.pegasys.artemis.util.bytes.BytesValue;

public class EmptyBytesValueGenerator extends Generator<BytesValue> {
public EmptyBytesValueGenerator() {
super(BytesValue.class);
}

@Override
public BytesValue generate(SourceOfRandomness random, GenerationStatus status) {
return BytesValue.EMPTY;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.ethereum.beacon.db.configuration;

import com.pholser.junit.quickcheck.generator.*;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;

import java.util.function.Function;

public class EmptyFunctionGenerator extends Generator<Function> {
public EmptyFunctionGenerator() {
super(Function.class);
}

@Override
public Function generate(SourceOfRandomness random, GenerationStatus status) {
return Function.identity();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.ethereum.beacon.db.configuration;

import com.pholser.junit.quickcheck.generator.*;
import com.pholser.junit.quickcheck.random.SourceOfRandomness;
import org.ethereum.beacon.db.source.DataSource;
import org.ethereum.beacon.db.source.impl.HashMapDataSource;

public class HashMapDatasourceGenerator extends Generator<DataSource> {
public HashMapDatasourceGenerator() {
super(DataSource.class);
}

@Override
public HashMapDataSource generate(SourceOfRandomness random, GenerationStatus status) {
return new HashMapDataSource();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.ethereum.beacon.db.source;

import com.pholser.junit.quickcheck.*;
import com.pholser.junit.quickcheck.runner.JUnitQuickcheck;
import org.ethereum.beacon.db.configuration.HashMapDatasourceGenerator;
import org.junit.runner.RunWith;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(JUnitQuickcheck.class)
public class WriteCacheImplTest {

private final String TEST_ENTITY_KEY = "TEST_ENTITY_KEY";

@Property
public void get(@From(HashMapDatasourceGenerator.class) DataSource dataSource) {
final CacheDataSource<String, String> cacheDataSource = new WriteCacheImpl<String, String>(dataSource);
assertThat(cacheDataSource.get(TEST_ENTITY_KEY)).isNotPresent();
}

@Property
public void getCacheEntry(@From(HashMapDatasourceGenerator.class) DataSource dataSource) {
final CacheDataSource<String, String> cacheDataSource = new WriteCacheImpl<String, String>(dataSource);
assertThat(cacheDataSource.get(TEST_ENTITY_KEY)).isNotPresent();
}
}