@@ -4,7 +4,8 @@ import java.io.File
4
4
import java .nio .file .Files
5
5
import akka .util .ByteString
6
6
import io .iohk .ethereum .ObjectGenerators
7
- import io .iohk .ethereum .db .dataSource .DataSource
7
+ import io .iohk .ethereum .db .dataSource .{DataSource , DataSourceUpdate }
8
+ import io .iohk .ethereum .db .dataSource .DataSource .{Key , Namespace , Value }
8
9
import org .scalatest .FlatSpec
9
10
import org .scalatestplus .scalacheck .ScalaCheckPropertyChecks
10
11
@@ -30,12 +31,19 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
30
31
}
31
32
}
32
33
34
+ def prepareUpdate (
35
+ namespace : Namespace = OtherNamespace ,
36
+ toRemove : Seq [Key ] = Nil ,
37
+ toUpsert : Seq [(Key , Value )] = Nil
38
+ ): Seq [DataSourceUpdate ] =
39
+ Seq (DataSourceUpdate (namespace, toRemove, toUpsert))
40
+
33
41
def updateInSeparateCalls (
34
- dataSource : DataSource ,
35
- toUpsert : Seq [(ByteString , ByteString )]
36
- ): DataSource = {
37
- toUpsert.foldLeft(dataSource) { case (recDB, keyValuePair) =>
38
- recDB .update(OtherNamespace , Seq (), Seq (keyValuePair))
42
+ dataSource : DataSource ,
43
+ toUpsert : Seq [(ByteString , ByteString )]
44
+ ): Unit = {
45
+ toUpsert.foreach { keyValuePair =>
46
+ dataSource .update(prepareUpdate(toUpsert = Seq (keyValuePair) ))
39
47
}
40
48
}
41
49
@@ -45,8 +53,9 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
45
53
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
46
54
withDir { path =>
47
55
val keyList = unFilteredKeyList.take(KeyNumberLimit )
48
- val db = updateInSeparateCalls(
49
- dataSource = createDataSource(path),
56
+ val db = createDataSource(path)
57
+ updateInSeparateCalls(
58
+ dataSource = db,
50
59
toUpsert = keyList.zip(keyList)
51
60
)
52
61
keyList.foreach { key =>
@@ -62,11 +71,8 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
62
71
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
63
72
withDir { path =>
64
73
val keyList = unFilteredKeyList.take(KeyNumberLimit )
65
- val db = createDataSource(path).update(
66
- OtherNamespace ,
67
- Seq (),
68
- keyList.zip(keyList)
69
- )
74
+ val db = createDataSource(path)
75
+ db.update(prepareUpdate(toUpsert = keyList.zip(keyList)))
70
76
71
77
keyList.foreach { key =>
72
78
assert(db.get(OtherNamespace , key).contains(key))
@@ -81,21 +87,18 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
81
87
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
82
88
withDir { path =>
83
89
val keyList = unFilteredKeyList.take(KeyNumberLimit )
84
- val db = createDataSource(path).update(
85
- OtherNamespace ,
86
- Seq (),
87
- keyList.zip(keyList)
88
- )
90
+ val db = createDataSource(path)
91
+ db.update(prepareUpdate(toUpsert = keyList.zip(keyList)))
89
92
90
93
val keyListWithExtraByte = keyList.map(1 .toByte +: _)
91
- val dbAfterUpdate =
92
- updateInSeparateCalls(db, keyList.zip(keyListWithExtraByte))
94
+ updateInSeparateCalls(db, keyList.zip(keyListWithExtraByte))
93
95
94
- keyList.zip(keyListWithExtraByte).foreach { case (key, value) =>
95
- assert(dbAfterUpdate.get(OtherNamespace , key).contains(value))
96
+ keyList.zip(keyListWithExtraByte).foreach {
97
+ case (key, value) =>
98
+ assert(db.get(OtherNamespace , key).contains(value))
96
99
}
97
100
98
- dbAfterUpdate .destroy()
101
+ db .destroy()
99
102
}
100
103
}
101
104
}
@@ -104,24 +107,18 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
104
107
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
105
108
withDir { path =>
106
109
val keyList = unFilteredKeyList.take(KeyNumberLimit )
107
- val db = createDataSource(path).update(
108
- OtherNamespace ,
109
- Seq (),
110
- keyList.zip(keyList)
111
- )
110
+ val db = createDataSource(path)
111
+ db.update(prepareUpdate(toUpsert = keyList.zip(keyList)))
112
112
113
113
val keyListWithExtraByte = keyList.map(1 .toByte +: _)
114
- val dbAfterUpdate = db.update(
115
- OtherNamespace ,
116
- Seq (),
117
- keyList.zip(keyListWithExtraByte)
118
- )
114
+ db.update(prepareUpdate(toUpsert = keyList.zip(keyListWithExtraByte)))
119
115
120
- keyList.zip(keyListWithExtraByte).foreach { case (key, value) =>
121
- assert(dbAfterUpdate.get(OtherNamespace , key).contains(value))
116
+ keyList.zip(keyListWithExtraByte).foreach {
117
+ case (key, value) =>
118
+ assert(db.get(OtherNamespace , key).contains(value))
122
119
}
123
120
124
- dbAfterUpdate .destroy()
121
+ db .destroy()
125
122
}
126
123
}
127
124
}
@@ -131,12 +128,8 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
131
128
withDir { path =>
132
129
val keyList = unFilteredKeyList.take(KeyNumberLimit )
133
130
val db = createDataSource(path)
134
- .update(
135
- namespace = OtherNamespace ,
136
- toRemove = Seq (),
137
- toUpsert = keyList.zip(keyList)
138
- )
139
- .clear
131
+ db.update(prepareUpdate(toUpsert = keyList.zip(keyList)))
132
+ db.clear()
140
133
141
134
keyList.foreach { key =>
142
135
assert(db.get(OtherNamespace , key).isEmpty)
@@ -151,11 +144,8 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
151
144
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
152
145
withDir { path =>
153
146
val keyList = unFilteredKeyList.take(KeyNumberLimit )
154
- val db = createDataSource(path).update(
155
- namespace = OtherNamespace ,
156
- toRemove = Seq (),
157
- toUpsert = keyList.zip(keyList)
158
- )
147
+ val db = createDataSource(path)
148
+ db.update(prepareUpdate(toUpsert = keyList.zip(keyList)))
159
149
db.close()
160
150
161
151
val dbAfterClose = createDataSource(path)
@@ -172,14 +162,11 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
172
162
withDir { path =>
173
163
forAll(seqByteStringOfNItemsGen(KeySizeWithoutPrefix )) { unFilteredKeyList : Seq [ByteString ] =>
174
164
val keyList = unFilteredKeyList.take(KeyNumberLimit )
175
- val db = createDataSource(path).update(
176
- namespace = OtherNamespace ,
177
- toRemove = Seq (),
178
- toUpsert = keyList.zip(keyList)
179
- )
165
+ val db = createDataSource(path)
166
+ db.update(prepareUpdate(toUpsert = keyList.zip(keyList)))
180
167
db.destroy()
181
168
182
- assert(! new File (path ).exists())
169
+ assert(! new File (" /tmp/iodbDestroy " ).exists())
183
170
184
171
val dbAfterDestroy = createDataSource(path)
185
172
keyList.foreach { key =>
@@ -199,15 +186,15 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
199
186
val db = createDataSource(path)
200
187
201
188
val valList1 = keyList.map(1 .toByte +: _)
202
- db.update(OtherNamespace , Seq (), keyList.zip(valList1))
189
+ db.update(prepareUpdate(namespace = OtherNamespace , toUpsert = keyList.zip(valList1) ))
203
190
204
191
val valList2 = keyList.map(2 .toByte +: _)
205
- db.update(OtherNamespace2 , Seq (), keyList.zip(valList2))
192
+ db.update(prepareUpdate(namespace = OtherNamespace2 , toUpsert = keyList.zip(valList2) ))
206
193
207
- keyList.zip(valList1).foreach { case (key, value) =>
208
- assert(db.get(OtherNamespace , key).contains(value))
194
+ keyList.zip(valList1).foreach {
195
+ case (key, value) =>
196
+ assert(db.get(OtherNamespace , key).contains(value))
209
197
}
210
-
211
198
keyList.zip(valList2).foreach { case (key, value) =>
212
199
assert(db.get(OtherNamespace2 , key).contains(value))
213
200
}
@@ -225,31 +212,31 @@ trait DataSourceIntegrationTestBehavior extends ScalaCheckPropertyChecks with Ob
225
212
val db = createDataSource(path)
226
213
227
214
val valList1 = keyList.map(1 .toByte +: _)
228
- db.update(OtherNamespace , Seq (), keyList.zip(valList1))
215
+ db.update(prepareUpdate(namespace = OtherNamespace , toUpsert = keyList.zip(valList1) ))
229
216
230
217
val valList2 = keyList.map(2 .toByte +: _)
231
- db.update(OtherNamespace2 , Seq (), keyList.zip(valList2))
218
+ db.update(prepareUpdate(namespace = OtherNamespace2 , toUpsert = keyList.zip(valList2) ))
232
219
233
220
// Removal of keys from the OtherNamespace namespace
234
- db.update(OtherNamespace , keyList, Nil )
221
+ db.update(prepareUpdate(namespace = OtherNamespace , toRemove = keyList) )
235
222
236
223
keyList.foreach { key =>
237
224
assert(db.get(OtherNamespace , key).isEmpty)
238
225
}
239
- keyList.zip(valList2).foreach { case (key, value) =>
240
- assert(db.get(OtherNamespace2 , key).contains(value))
226
+ keyList.zip(valList2).foreach {
227
+ case (key, value) =>
228
+ assert(db.get(OtherNamespace2 , key).contains(value))
241
229
}
242
230
243
231
// Removal of keys from the OtherNamespace2 namespace
244
- db.update(OtherNamespace2 , keyList, Nil )
232
+ db.update(prepareUpdate(namespace = OtherNamespace2 , toRemove = keyList) )
245
233
246
234
keyList.foreach { key =>
247
235
assert(db.get(OtherNamespace , key).isEmpty)
248
236
}
249
237
keyList.foreach { key =>
250
238
assert(db.get(OtherNamespace2 , key).isEmpty)
251
239
}
252
-
253
240
db.destroy()
254
241
}
255
242
}
0 commit comments