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