@@ -29,8 +29,10 @@ import org.junit.Assert.assertEquals
29
29
import org.junit.Test
30
30
import java.io.ByteArrayInputStream
31
31
import java.io.ByteArrayOutputStream
32
+ import java.io.IOException
32
33
import java.io.OutputStream
33
34
import kotlin.random.Random
35
+ import kotlin.test.assertFailsWith
34
36
35
37
internal class ChunkWriterTest {
36
38
@@ -116,7 +118,7 @@ internal class ChunkWriterTest {
116
118
every { chunksCache.insert(chunks[1 ].toCachedChunk(3 )) } just Runs
117
119
every { chunksCache.insert(chunks[2 ].toCachedChunk(3 )) } just Runs
118
120
119
- chunkWriter.writeChunk(inputStream, chunks, emptyList())
121
+ chunkWriter.writeChunk(inputStream, chunks, emptyList()) { false }
120
122
121
123
// check that version was written as the first byte
122
124
outputStreams.forEach { outputStream ->
@@ -171,7 +173,7 @@ internal class ChunkWriterTest {
171
173
// insert last not cached chunk into cache after upload
172
174
every { chunksCache.insert(chunks[2 ].toCachedChunk(3 )) } just Runs
173
175
174
- chunkWriter.writeChunk(inputStream, chunks, listOf (chunkId1))
176
+ chunkWriter.writeChunk(inputStream, chunks, listOf (chunkId1)) { false }
175
177
176
178
// check that output matches chunk data
177
179
assertEquals(VERSION , chunk1Output.toByteArray()[0 ])
@@ -234,7 +236,7 @@ internal class ChunkWriterTest {
234
236
chunksCache.insert(chunks[2 ].toCachedChunk(chunk3Bytes.size.toLong() + 1 ))
235
237
} just Runs
236
238
237
- chunkWriter.writeChunk(inputStream, chunks, emptyList())
239
+ chunkWriter.writeChunk(inputStream, chunks, emptyList()) { false }
238
240
239
241
// check that version and wrapped key was written as the first byte
240
242
outputStreams.forEach { outputStream ->
@@ -291,7 +293,7 @@ internal class ChunkWriterTest {
291
293
chunksCache.insert(chunks[0 ].toCachedChunk(chunkBytes.size.toLong() + 1 ))
292
294
} just Runs
293
295
294
- chunkWriter.writeChunk(inputStream, chunks, emptyList())
296
+ chunkWriter.writeChunk(inputStream, chunks, emptyList()) { false }
295
297
296
298
// check that output matches chunk data
297
299
assertEquals(1 + chunks[0 ].plaintextSize.toInt(), chunkOutput1.size())
@@ -313,6 +315,20 @@ internal class ChunkWriterTest {
313
315
assertEquals(chunkOutput3.size().toLong(), size2)
314
316
}
315
317
318
+ @Test
319
+ fun testAbort () = runBlocking {
320
+ val chunkBytes = Random .nextBytes(16 * 1024 * 1024 )
321
+ val inputStream = ByteArrayInputStream (chunkBytes)
322
+ val chunks = listOf (
323
+ Chunk (chunkId1, 0 , chunkBytes.size.toLong()),
324
+ )
325
+
326
+ val e = assertFailsWith<IOException > {
327
+ chunkWriter.writeChunk(inputStream, chunks, emptyList()) { true }
328
+ }
329
+ assertEquals(" Metered Network" , e.message)
330
+ }
331
+
316
332
private fun MockKMatcherScope.bytes (size : Int ) = match<ByteArray > {
317
333
it.size == size
318
334
}
0 commit comments