1
1
package com .advancedtelematic .treehub .object_store
2
2
3
+ import java .io .File
4
+
3
5
import akka .actor .ActorSystem
4
6
import akka .http .scaladsl .model .StatusCodes
5
7
import akka .stream .ActorMaterializer
6
- import akka .stream .scaladsl .Source
8
+ import akka .stream .scaladsl .{ FileIO , Source }
7
9
import akka .util .ByteString
8
10
import com .advancedtelematic .data .DataType .{ObjectId , ObjectIdOps , ObjectStatus , TObject }
9
11
import com .advancedtelematic .util .TreeHubSpec
@@ -22,22 +24,24 @@ class S3BlobStoreIntegrationSpec extends TreeHubSpec {
22
24
23
25
val s3BlobStore = new S3BlobStore (s3Credentials, true )
24
26
25
- override implicit def patienceConfig = PatienceConfig ().copy(timeout = Span (3 , Seconds ))
27
+ override implicit def patienceConfig = PatienceConfig ().copy(timeout = Span (15 , Seconds ))
26
28
27
29
test(" can store object" ) {
28
30
val tobj = TObject (defaultNs, ObjectId .parse(" ce720e82a727efa4b30a6ab73cefe31a8d4ec6c0d197d721f07605913d2a279a.commit" ).toOption.get, 0L , ObjectStatus .UPLOADED )
31
+ val blob = ByteString (" this is byte." )
29
32
30
- val source = Source .single(ByteString ( " this is byte. " ) )
33
+ val source = Source .single(blob )
31
34
32
35
val size = s3BlobStore.store(defaultNs, tobj.id, source).futureValue
33
36
34
37
size shouldBe 13
35
38
}
36
39
37
- test(" can retrieve an object" ) {
40
+ test(" can retrieve big object" ) {
38
41
val tobj = TObject (defaultNs, ObjectId .parse(" ce720e82a727efa4b30a6ab73cefe31a8d4ec6c0d197d721f07605913d2a279a.commit" ).toOption.get, 0L , ObjectStatus .UPLOADED )
42
+ val blob = ByteString (" this is byte. Call me. maybe." )
39
43
40
- val source = Source .single(ByteString ( " this is byte. Call me. maybe. " ) )
44
+ val source = Source .single(blob )
41
45
42
46
val f = async {
43
47
await(s3BlobStore.store(defaultNs, tobj.id, source))
@@ -48,10 +52,28 @@ class S3BlobStoreIntegrationSpec extends TreeHubSpec {
48
52
s3BlobStore.exists(tobj.namespace, tobj.id).futureValue shouldBe true
49
53
}
50
54
55
+
56
+ test(" XXX can retrieve an object" ) {
57
+ val file = new File (this .getClass.getResource(s " /blobs/myfile.bin " ).getFile)
58
+ val source = FileIO .fromPath(file.toPath)
59
+ val tobj = TObject (defaultNs, ObjectId .parse(" 625e61876cbe98fbf164c8ce5975c6d69a4ba0e9fa57c729ea06d02fd966a9cc.file" ).toOption.get, 0L , ObjectStatus .UPLOADED )
60
+
61
+ val f = async {
62
+ await(s3BlobStore.store(defaultNs, tobj.id, source))
63
+
64
+ println(" upload finished" )
65
+
66
+ await(s3BlobStore.readFull(tobj.namespace, tobj.id))
67
+ }
68
+
69
+ f.futureValue.size shouldBe file.length()
70
+ s3BlobStore.exists(tobj.namespace, tobj.id).futureValue shouldBe true
71
+ }
72
+
51
73
test(" build response builds a redirect" ) {
52
74
val tobj = TObject (defaultNs, ObjectId .parse(" ce720e82a727efa4b30a6ab73cefe31a8d4ec6c0d197d721f07605913d2a279a.commit" ).toOption.get, 0L , ObjectStatus .UPLOADED )
53
-
54
- val source = Source .single(ByteString ( " this is byte. Call me. maybe. " ) )
75
+ val blob = ByteString ( " this is byte. Call me. maybe. " )
76
+ val source = Source .single(blob )
55
77
56
78
val response = async {
57
79
await(s3BlobStore.store(defaultNs, tobj.id, source))
@@ -63,9 +85,11 @@ class S3BlobStoreIntegrationSpec extends TreeHubSpec {
63
85
}
64
86
65
87
test(" build response a response containing the object content" ) {
66
- val tobj = TObject (defaultNs, ObjectId .parse( " ce720e82a727efa4b30a6ab73cefe31a8d4ec6c0d197d721f07605913d2a279a.commit " ).toOption.get, 0L , ObjectStatus . UPLOADED )
88
+ pending
67
89
68
- val source = Source .single(ByteString (" this is byte. Call me. maybe." ))
90
+ val tobj = TObject (defaultNs, ObjectId .parse(" ce720e82a727efa4b30a6ab73cefe31a8d4ec6c0d197d721f07605913d2a279a.commit" ).toOption.get, 0L , ObjectStatus .UPLOADED )
91
+ val blob = ByteString (" this is byte. Call me. maybe." )
92
+ val source = Source .single(blob)
69
93
70
94
val response = async {
71
95
await(s3BlobStore.store(defaultNs, tobj.id, source))
@@ -75,5 +99,4 @@ class S3BlobStoreIntegrationSpec extends TreeHubSpec {
75
99
response.status shouldBe StatusCodes .OK
76
100
response.entity.dataBytes.runFold(ByteString .empty)(_ ++ _).futureValue.utf8String shouldBe " this is byte. Call me. maybe."
77
101
}
78
-
79
102
}
0 commit comments