Skip to content

Commit

Permalink
[RFR-1057] Upgrade uploader to 1.4.1
Browse files Browse the repository at this point in the history
Task/rfr 1057 upgrade uploader
  • Loading branch information
hb0 authored Jul 16, 2024
2 parents fece297 + 381f683 commit ee4f211
Show file tree
Hide file tree
Showing 13 changed files with 177 additions and 161 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/gradle_build.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This workflow ensures the building step works
#
# @author Armin Schnabel
# @version 1.0.3
# @since 5.0.0
name: Gradle Build

on:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/gradle_connected-tests.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This workflow ensures the connected tests keep working
#
# @author Armin Schnabel
# @version 1.0.0
# @since 7.4.0
name: Gradle Connected Tests

on:
Expand Down
2 changes: 0 additions & 2 deletions .github/workflows/gradle_publish.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# This workflow publishes a new version to the Github Registry.
#
# @author Armin Schnabel
# @version 1.1.0
# @since 5.0.0
name: Gradle Publish

on:
Expand Down
8 changes: 3 additions & 5 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 Cyface GmbH
* Copyright 2017-2024 Cyface GmbH
*
* This file is part of the Cyface SDK for Android.
*
Expand All @@ -21,8 +21,6 @@
*
* @author Armin Schnabel
* @author Klemens Muthmann
* @version 2.11.0
* @since 1.0.0
*/

buildscript {
Expand Down Expand Up @@ -54,8 +52,8 @@ ext {
// (!) Match versions `android-app`, `SDK` and `camera-service`.
// When `android-app` is checkout out, `rootProject.uploaderVersion` in the submodules will point
// to `android-app/build.gradle` instead of `submodule/build.gradle`.
cyfaceSerializationVersion = "3.2.0"
cyfaceUploaderVersion = "1.3.0"
cyfaceSerializationVersion = "3.4.0"
cyfaceUploaderVersion = "1.4.1"

// Android SDK versions
minSdkVersion = 21 // device support
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2023 Cyface GmbH
* Copyright 2017-2024 Cyface GmbH
*
* This file is part of the Cyface SDK for Android.
*
Expand Down Expand Up @@ -46,13 +46,11 @@ import de.cyface.persistence.model.Measurement
import de.cyface.persistence.model.MeasurementStatus
import de.cyface.persistence.model.Modality
import de.cyface.synchronization.CyfaceAuthenticator
import de.cyface.synchronization.settings.DefaultSynchronizationSettings
import de.cyface.testutils.SharedTestUtils.clearPersistenceLayer
import de.cyface.utils.Validate
import kotlinx.coroutines.runBlocking
import org.hamcrest.CoreMatchers
import org.hamcrest.MatcherAssert.assertThat
import org.json.JSONObject
import org.junit.After
import org.junit.Before
import org.junit.Ignore
Expand All @@ -70,8 +68,6 @@ import java.util.concurrent.locks.ReentrantLock
*
* @author Klemens Muthmann
* @author Armin Schnabel
* @version 5.7.8
* @since 2.0.0
*/
@RunWith(AndroidJUnit4::class)
@LargeTest
Expand Down Expand Up @@ -224,7 +220,7 @@ class DataCapturingServiceTest {
* @throws DataCapturingException If the asynchronous background service did not start successfully or no valid
* Android context was available.
* @throws MissingPermissionException If no Android `ACCESS_FINE_LOCATION` has been granted. You may
* register a [de.cyface.datacapturing.ui.UIListener] to ask the user for this permission and prevent the
* register a `de.cyface.datacapturing.ui.UIListener` to ask the user for this permission and prevent the
* `Exception`. If the `Exception` was thrown the service does not start.
*/
@Throws(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023 Cyface GmbH
* Copyright 2023-2024 Cyface GmbH
*
* This file is part of the Cyface SDK for Android.
*
Expand All @@ -18,10 +18,11 @@
*/
package de.cyface.synchronization

import de.cyface.model.RequestMetaData
import de.cyface.uploader.Result
import de.cyface.uploader.UploadProgressListener
import de.cyface.uploader.Uploader
import de.cyface.uploader.model.Attachment
import de.cyface.uploader.model.Measurement
import java.io.File
import java.net.MalformedURLException
import java.net.URL
Expand All @@ -30,8 +31,6 @@ import java.net.URL
* An [Uploader] that does not actually connect to the server, for testing.
*
* @author Armin Schnabel
* @version 2.0.0
* @since 7.7.0
*/
internal class MockedUploader : Uploader {

Expand All @@ -43,17 +42,17 @@ internal class MockedUploader : Uploader {
}
}

override fun attachmentsEndpoint(measurementId: Long): URL {
override fun attachmentsEndpoint(deviceId: String, measurementId: Long): URL {
return try {
URL("https://mocked.cyface.de/api/v123/measurements/ID/attachments")
URL("https://mocked.cyface.de/api/v123/measurements/did/mid/attachments")
} catch (e: MalformedURLException) {
throw IllegalStateException(e)
}
}

override fun uploadMeasurement(
jwtToken: String,
metaData: RequestMetaData,
uploadable: Measurement,
file: File,
progressListener: UploadProgressListener
): Result {
Expand All @@ -63,13 +62,12 @@ internal class MockedUploader : Uploader {

override fun uploadAttachment(
jwtToken: String,
metaData: RequestMetaData,
measurementId: Long,
uploadable: Attachment,
file: File,
fileName: String,
progressListener: UploadProgressListener
): Result {
progressListener.updatedProgress(1.0f) // 100%
return Result.UPLOAD_SUCCESSFUL
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 Cyface GmbH
* Copyright 2018-2024 Cyface GmbH
*
* This file is part of the Cyface SDK for Android.
*
Expand All @@ -24,7 +24,6 @@ import android.util.Log
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry
import de.cyface.model.RequestMetaData
import de.cyface.persistence.DefaultPersistenceBehaviour
import de.cyface.persistence.DefaultPersistenceLayer
import de.cyface.persistence.exception.NoSuchMeasurementException
Expand Down Expand Up @@ -56,6 +55,13 @@ import de.cyface.uploader.exception.UnauthorizedException
import de.cyface.uploader.exception.UnexpectedResponseCode
import de.cyface.uploader.exception.UploadFailed
import de.cyface.uploader.exception.UploadSessionExpired
import de.cyface.uploader.model.Attachment
import de.cyface.uploader.model.MeasurementIdentifier
import de.cyface.uploader.model.metadata.ApplicationMetaData
import de.cyface.uploader.model.metadata.AttachmentMetaData
import de.cyface.uploader.model.metadata.DeviceMetaData
import de.cyface.uploader.model.metadata.GeoLocation
import de.cyface.uploader.model.metadata.MeasurementMetaData
import de.cyface.utils.CursorIsNullException
import kotlinx.coroutines.runBlocking
import org.hamcrest.CoreMatchers
Expand All @@ -68,6 +74,7 @@ import java.io.File
import java.net.URL
import java.nio.file.Files
import java.nio.file.Path
import java.util.UUID

/**
* Tests the data transmission code.
Expand All @@ -76,8 +83,6 @@ import java.nio.file.Path
*
* @author Klemens Muthmann
* @author Armin Schnabel
* @version 1.1.0
* @since 7.7.0
*/
@RunWith(AndroidJUnit4::class)
@LargeTest
Expand Down Expand Up @@ -140,14 +145,22 @@ class SyncPerformerTest {
MatcherAssert.assertThat(loadedStatus, CoreMatchers.equalTo(MeasurementStatus.FINISHED))
val compressedTransferTempFile = loadSerializedCompressed(persistence, measurementId)
val metaData =
loadMetaData(persistence, measurement, locationCount, logCount, imageCount, videoCount, filesSize)
loadMetaData(
persistence,
measurement,
locationCount,
logCount,
imageCount,
videoCount,
filesSize
)
val progressListener = object : UploadProgressListener {
override fun updatedProgress(percent: Float) {
Log.d(TAG, String.format("Upload Progress %f", percent))
}
}
val fileName =
"${metaData.deviceIdentifier}_${metaData.measurementIdentifier}.${SyncAdapter.COMPRESSED_TRANSFER_FILE_EXTENSION}"
"${metaData.identifier.deviceIdentifier}_${metaData.identifier.measurementIdentifier}.${SyncAdapter.COMPRESSED_TRANSFER_FILE_EXTENSION}"
val uploader = MockedUploader()

// Prepare transmission
Expand Down Expand Up @@ -178,12 +191,12 @@ class SyncPerformerTest {
@Test
@Throws(CursorIsNullException::class, NoSuchMeasurementException::class)
fun testSendData() = runBlocking {
performSendDataTest(
point3DCount = 600 * 1000,
locationCount = 3 * 1000,
0, 0, 0, 0
)
}
performSendDataTest(
point3DCount = 600 * 1000,
locationCount = 3 * 1000,
0, 0, 0, 0
)
}

/**
* Tests the basic transmission with a measurement with attached files.
Expand Down Expand Up @@ -263,43 +276,50 @@ class SyncPerformerTest {
val startLocation = tracks[0].geoLocations[0]!!
val lastTrack = tracks[tracks.size - 1].geoLocations
val endLocation = lastTrack[lastTrack.size - 1]!!
val deviceId = "testDevi-ce00-42b6-a840-1b70d30094b8" // Must be a valid UUID
val startRecord = RequestMetaData.GeoLocation(
val deviceId = UUID.randomUUID()
val startRecord = GeoLocation(
startLocation.timestamp,
startLocation.lat,
startLocation.lon
)
val endRecord = RequestMetaData.GeoLocation(
val endRecord = GeoLocation(
endLocation.timestamp, endLocation.lat,
endLocation.lon
)
val metaData = RequestMetaData(
deviceId, measurementIdentifier.toString(),
"testOsVersion", "testDeviceType", "testAppVersion",
distance, locationCount.toLong(), startRecord, endRecord,
Modality.BICYCLE.databaseIdentifier, 3, 0, 0, 0, 0
val metaData = de.cyface.uploader.model.Measurement(
MeasurementIdentifier(deviceId, measurementIdentifier),
DeviceMetaData("testOsVersion", "testDeviceType"),
ApplicationMetaData("testAppVersion", 3),
MeasurementMetaData(
distance,
locationCount.toLong(),
startRecord,
endRecord,
Modality.BICYCLE.databaseIdentifier,
),
AttachmentMetaData(0, 0, 0, 0),
)
val progressListener = object : UploadProgressListener {
override fun updatedProgress(percent: Float) {
Log.d(TAG, String.format("Upload Progress %f", percent))
}
}
val fileName =
"${metaData.deviceIdentifier}_${metaData.measurementIdentifier}.${SyncAdapter.COMPRESSED_TRANSFER_FILE_EXTENSION}"
"${metaData.identifier.deviceIdentifier}_${metaData.identifier.measurementIdentifier}.${SyncAdapter.COMPRESSED_TRANSFER_FILE_EXTENSION}"

// Mock the actual post request
val mockedUploader = object : Uploader {
override fun measurementsEndpoint(): URL {
return URL("https://mocked.cyface.de/api/v123/measurements")
}

override fun attachmentsEndpoint(measurementId: Long): URL {
return URL("https://mocked.cyface.de/api/v123/measurements/$measurementId/attachments")
override fun attachmentsEndpoint(deviceId: String, measurementId: Long): URL {
return URL("https://mocked.cyface.de/api/v123/measurements/$deviceId/$measurementId/attachments")
}

override fun uploadMeasurement(
jwtToken: String,
metaData: RequestMetaData,
uploadable: de.cyface.uploader.model.Measurement,
file: File,
progressListener: UploadProgressListener
): Result {
Expand All @@ -308,8 +328,7 @@ class SyncPerformerTest {

override fun uploadAttachment(
jwtToken: String,
metaData: RequestMetaData,
measurementId: Long,
uploadable: Attachment,
file: File,
fileName: String,
progressListener: UploadProgressListener
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2023 Cyface GmbH
* Copyright 2018-2024 Cyface GmbH
*
* This file is part of the Cyface SDK for Android.
*
Expand All @@ -23,7 +23,6 @@ import android.content.Context
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import androidx.test.platform.app.InstrumentationRegistry
import de.cyface.model.RequestMetaData
import de.cyface.persistence.DefaultPersistenceBehaviour
import de.cyface.persistence.DefaultPersistenceLayer
import de.cyface.persistence.exception.NoSuchMeasurementException
Expand Down Expand Up @@ -72,8 +71,6 @@ import java.io.IOException
*
* @author Klemens Muthmann
* @author Armin Schnabel
* @version 2.1.3
* @since 2.0.0
* @see [Testing documentation](http://d.android.com/tools/testing)
*/
@RunWith(AndroidJUnit4::class)
Expand Down Expand Up @@ -148,7 +145,7 @@ class SyncPerformerTestWithoutAuth {
)
)
file = loadSerializedCompressed(persistence, measurementIdentifier)
val metaData: RequestMetaData =
val metaData =
loadMetaData(persistence, measurement, locationCount, 0, 0, 0, 0)
val url = "$TEST_API_URL/api/v3/measurements"

Expand Down
Loading

0 comments on commit ee4f211

Please sign in to comment.