22
22
package com.owncloud.android.lib.resources.files.webdav
23
23
24
24
import com.owncloud.android.AbstractIT
25
+ import com.owncloud.android.lib.common.network.WebdavEntry
26
+ import com.owncloud.android.lib.common.network.WebdavUtils
25
27
import com.owncloud.android.lib.common.operations.RemoteOperationResult
26
28
import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode
27
29
import com.owncloud.android.lib.resources.files.ChunkedFileUploadRemoteOperation
28
30
import junit.framework.TestCase
29
31
import junit.framework.TestCase.assertNotNull
30
32
import junit.framework.TestCase.assertTrue
33
+ import org.apache.jackrabbit.webdav.client.methods.PropFindMethod
31
34
import org.junit.Test
35
+ import java.io.File
32
36
33
37
class ChunkedFileUploadRemoteOperationIT : AbstractIT () {
34
38
@Test
@@ -70,6 +74,65 @@ class ChunkedFileUploadRemoteOperationIT : AbstractIT() {
70
74
TestCase .assertSame(ResultCode .CANCELLED , uploadResult?.code)
71
75
}
72
76
77
+ @Test
78
+ fun resume () {
79
+ val filePath = createFile(" chunkedFile.txt" , BIG_FILE_ITERATION * 2 )
80
+ val timestamp = System .currentTimeMillis() / MILLI_TO_SECOND
81
+ val remotePath = " /bigFile.md"
82
+
83
+ // set up first upload
84
+ var sut = ChunkedFileUploadRemoteOperation (
85
+ filePath,
86
+ remotePath,
87
+ " text/markdown" ,
88
+ " " ,
89
+ RANDOM_MTIME ,
90
+ timestamp,
91
+ false ,
92
+ true
93
+ )
94
+
95
+ // start first upload
96
+ var uploadResult: RemoteOperationResult <String >? = null
97
+ Thread {
98
+ uploadResult = sut.execute(client)
99
+ }.start()
100
+
101
+ // delay and cancel upload
102
+ shortSleep()
103
+ shortSleep()
104
+ sut.cancel(ResultCode .CANCELLED )
105
+
106
+ for (i in 1 .. MAX_TRIES ) {
107
+ shortSleep()
108
+
109
+ if (uploadResult != null ) {
110
+ break
111
+ }
112
+ }
113
+
114
+ // start second upload of same file
115
+ sut = ChunkedFileUploadRemoteOperation (
116
+ filePath,
117
+ remotePath,
118
+ " text/markdown" ,
119
+ " " ,
120
+ RANDOM_MTIME ,
121
+ timestamp,
122
+ false ,
123
+ true
124
+ )
125
+
126
+ // reset result; start second upload
127
+ uploadResult = null
128
+ uploadResult = sut.execute(client)
129
+
130
+ // second upload should succeed
131
+ assert (uploadResult?.isSuccess == true )
132
+
133
+ assert (File (filePath).length() == getRemoteSize(remotePath))
134
+ }
135
+
73
136
private fun genLargeUpload (onWifiConnection : Boolean ): ChunkedFileUploadRemoteOperation {
74
137
// create file
75
138
val filePath = createFile(" chunkedFile.txt" , BIG_FILE_ITERATION )
@@ -87,6 +150,15 @@ class ChunkedFileUploadRemoteOperationIT : AbstractIT() {
87
150
)
88
151
}
89
152
153
+ private fun getRemoteSize (remotePath : String ): Long {
154
+ val davPath = client.filesDavUri.toString() + " /" + WebdavUtils .encodePath(remotePath)
155
+ val propFindMethod = PropFindMethod (davPath, WebdavUtils .getFilePropSet(), 0 )
156
+ client.executeMethod(propFindMethod)
157
+ assert (propFindMethod.succeeded())
158
+
159
+ return WebdavEntry (propFindMethod.responseBodyAsMultiStatus.responses[0 ], remotePath).contentLength
160
+ }
161
+
90
162
companion object {
91
163
const val BIG_FILE_ITERATION = 1000000
92
164
const val MAX_TRIES = 30
0 commit comments