@@ -2,16 +2,13 @@ package io.iohk.ethereum.db
2
2
3
3
import java .io .File
4
4
import java .nio .file .Files
5
-
6
5
import akka .util .ByteString
7
6
import io .iohk .ethereum .ObjectGenerators
8
7
import io .iohk .ethereum .db .dataSource .DataSource
9
8
import org .scalatest .FlatSpec
10
- import org .scalatest . prop . PropertyChecks
9
+ import org .scalatestplus . scalacheck . ScalaCheckPropertyChecks
11
10
12
- trait DataSourceIntegrationTestBehavior
13
- extends PropertyChecks
14
- with ObjectGenerators {
11
+ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with ObjectGenerators {
15
12
16
13
this : FlatSpec =>
17
14
@@ -23,7 +20,6 @@ trait DataSourceIntegrationTestBehavior
23
20
24
21
val MaxIncreaseInLength = 10
25
22
26
-
27
23
def withDir (testCode : String => Any ): Unit = {
28
24
val path = Files .createTempDirectory(" testdb" ).getFileName.toString
29
25
try {
@@ -34,7 +30,10 @@ trait DataSourceIntegrationTestBehavior
34
30
}
35
31
}
36
32
37
- def updateInSeparateCalls (dataSource : DataSource , toUpsert : Seq [(ByteString , ByteString )]): DataSource = {
33
+ def updateInSeparateCalls (
34
+ dataSource : DataSource ,
35
+ toUpsert : Seq [(ByteString , ByteString )]
36
+ ): DataSource = {
38
37
toUpsert.foldLeft(dataSource) { case (recDB, keyValuePair) =>
39
38
recDB.update(OtherNamespace , Seq (), Seq (keyValuePair))
40
39
}
@@ -50,7 +49,9 @@ trait DataSourceIntegrationTestBehavior
50
49
dataSource = createDataSource(path),
51
50
toUpsert = keyList.zip(keyList)
52
51
)
53
- keyList.foreach { key => assert(db.get(OtherNamespace , key).contains(key)) }
52
+ keyList.foreach { key =>
53
+ assert(db.get(OtherNamespace , key).contains(key))
54
+ }
54
55
55
56
db.destroy()
56
57
}
@@ -61,9 +62,15 @@ trait DataSourceIntegrationTestBehavior
61
62
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
62
63
withDir { path =>
63
64
val keyList = unFilteredKeyList.take(KeyNumberLimit )
64
- val db = createDataSource(path).update(OtherNamespace , Seq (), keyList.zip(keyList))
65
+ val db = createDataSource(path).update(
66
+ OtherNamespace ,
67
+ Seq (),
68
+ keyList.zip(keyList)
69
+ )
65
70
66
- keyList.foreach { key => assert(db.get(OtherNamespace , key).contains(key)) }
71
+ keyList.foreach { key =>
72
+ assert(db.get(OtherNamespace , key).contains(key))
73
+ }
67
74
68
75
db.destroy()
69
76
}
@@ -74,10 +81,15 @@ trait DataSourceIntegrationTestBehavior
74
81
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
75
82
withDir { path =>
76
83
val keyList = unFilteredKeyList.take(KeyNumberLimit )
77
- val db = createDataSource(path).update(OtherNamespace , Seq (), keyList.zip(keyList))
84
+ val db = createDataSource(path).update(
85
+ OtherNamespace ,
86
+ Seq (),
87
+ keyList.zip(keyList)
88
+ )
78
89
79
90
val keyListWithExtraByte = keyList.map(1 .toByte +: _)
80
- val dbAfterUpdate = updateInSeparateCalls(db, keyList.zip(keyListWithExtraByte))
91
+ val dbAfterUpdate =
92
+ updateInSeparateCalls(db, keyList.zip(keyListWithExtraByte))
81
93
82
94
keyList.zip(keyListWithExtraByte).foreach { case (key, value) =>
83
95
assert(dbAfterUpdate.get(OtherNamespace , key).contains(value))
@@ -92,10 +104,18 @@ trait DataSourceIntegrationTestBehavior
92
104
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
93
105
withDir { path =>
94
106
val keyList = unFilteredKeyList.take(KeyNumberLimit )
95
- val db = createDataSource(path).update(OtherNamespace , Seq (), keyList.zip(keyList))
107
+ val db = createDataSource(path).update(
108
+ OtherNamespace ,
109
+ Seq (),
110
+ keyList.zip(keyList)
111
+ )
96
112
97
113
val keyListWithExtraByte = keyList.map(1 .toByte +: _)
98
- val dbAfterUpdate = db.update(OtherNamespace , Seq (), keyList.zip(keyListWithExtraByte))
114
+ val dbAfterUpdate = db.update(
115
+ OtherNamespace ,
116
+ Seq (),
117
+ keyList.zip(keyListWithExtraByte)
118
+ )
99
119
100
120
keyList.zip(keyListWithExtraByte).foreach { case (key, value) =>
101
121
assert(dbAfterUpdate.get(OtherNamespace , key).contains(value))
@@ -110,10 +130,17 @@ trait DataSourceIntegrationTestBehavior
110
130
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
111
131
withDir { path =>
112
132
val keyList = unFilteredKeyList.take(KeyNumberLimit )
113
- val db = createDataSource(path).update(namespace = OtherNamespace , toRemove = Seq (), toUpsert = keyList.zip(keyList))
133
+ val db = createDataSource(path)
134
+ .update(
135
+ namespace = OtherNamespace ,
136
+ toRemove = Seq (),
137
+ toUpsert = keyList.zip(keyList)
138
+ )
114
139
.clear
115
140
116
- keyList.foreach { key => assert(db.get(OtherNamespace , key).isEmpty) }
141
+ keyList.foreach { key =>
142
+ assert(db.get(OtherNamespace , key).isEmpty)
143
+ }
117
144
118
145
db.destroy()
119
146
}
@@ -124,11 +151,17 @@ trait DataSourceIntegrationTestBehavior
124
151
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
125
152
withDir { path =>
126
153
val keyList = unFilteredKeyList.take(KeyNumberLimit )
127
- val db = createDataSource(path).update(namespace = OtherNamespace , toRemove = Seq (), toUpsert = keyList.zip(keyList))
154
+ val db = createDataSource(path).update(
155
+ namespace = OtherNamespace ,
156
+ toRemove = Seq (),
157
+ toUpsert = keyList.zip(keyList)
158
+ )
128
159
db.close()
129
160
130
161
val dbAfterClose = createDataSource(path)
131
- keyList.foreach { key => assert(dbAfterClose.get(OtherNamespace , key).contains(key)) }
162
+ keyList.foreach { key =>
163
+ assert(dbAfterClose.get(OtherNamespace , key).contains(key))
164
+ }
132
165
133
166
dbAfterClose.destroy()
134
167
}
@@ -139,13 +172,19 @@ trait DataSourceIntegrationTestBehavior
139
172
withDir { path =>
140
173
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
141
174
val keyList = unFilteredKeyList.take(KeyNumberLimit )
142
- val db = createDataSource(path).update(namespace = OtherNamespace , toRemove = Seq (), toUpsert = keyList.zip(keyList))
175
+ val db = createDataSource(path).update(
176
+ namespace = OtherNamespace ,
177
+ toRemove = Seq (),
178
+ toUpsert = keyList.zip(keyList)
179
+ )
143
180
db.destroy()
144
181
145
182
assert(! new File (path).exists())
146
183
147
184
val dbAfterDestroy = createDataSource(path)
148
- keyList.foreach { key => assert(dbAfterDestroy.get(OtherNamespace , key).isEmpty) }
185
+ keyList.foreach { key =>
186
+ assert(dbAfterDestroy.get(OtherNamespace , key).isEmpty)
187
+ }
149
188
150
189
dbAfterDestroy.destroy()
151
190
}
@@ -194,16 +233,22 @@ trait DataSourceIntegrationTestBehavior
194
233
// Removal of keys from the OtherNamespace namespace
195
234
db.update(OtherNamespace , keyList, Nil )
196
235
197
- keyList.foreach { key => assert(db.get(OtherNamespace , key).isEmpty) }
236
+ keyList.foreach { key =>
237
+ assert(db.get(OtherNamespace , key).isEmpty)
238
+ }
198
239
keyList.zip(valList2).foreach { case (key, value) =>
199
240
assert(db.get(OtherNamespace2 , key).contains(value))
200
241
}
201
242
202
243
// Removal of keys from the OtherNamespace2 namespace
203
244
db.update(OtherNamespace2 , keyList, Nil )
204
245
205
- keyList.foreach { key => assert(db.get(OtherNamespace , key).isEmpty) }
206
- keyList.foreach { key => assert(db.get(OtherNamespace2 , key).isEmpty) }
246
+ keyList.foreach { key =>
247
+ assert(db.get(OtherNamespace , key).isEmpty)
248
+ }
249
+ keyList.foreach { key =>
250
+ assert(db.get(OtherNamespace2 , key).isEmpty)
251
+ }
207
252
208
253
db.destroy()
209
254
}
0 commit comments