test setup

This commit is contained in:
Martin Ptáček
2023-06-15 11:42:59 +02:00
parent de8a00bda5
commit 4c5ee4d982
5 changed files with 34 additions and 8 deletions

View File

@ -47,6 +47,9 @@ android {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
testOptions {
execution 'ANDROIDX_TEST_ORCHESTRATOR'
}
}
protobuf {
@ -61,7 +64,13 @@ protobuf {
}
dependencies {
// custom -tests
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestUtil 'androidx.test:orchestrator:1.4.2'
// custom - work manager
implementation 'androidx.work:work-multiprocess:2.8.1'
def core_version = "1.10.1"
// custom - prometheus client java library

View File

@ -16,7 +16,9 @@ class ExponentialBackoff {
suspend fun runWithBackoff(
function: suspend () -> Unit,
onException: () -> Unit, infinite: Boolean = true
onException: () -> Unit,
debugLabel: String,
infinite: Boolean = true,
) {
var successfull = false
@ -38,7 +40,8 @@ class ExponentialBackoff {
}
}
Log.d(TAG, "Exception caught")
Log.d(TAG, "Debug label: $debugLabel Exception caught")
Log.d(TAG, "Exception: $e")
onException()
@ -52,7 +55,7 @@ class ExponentialBackoff {
break
}
Log.d(TAG, "Backoff with delay: $currentDelay seconds")
Log.d(TAG, "Label :$debugLabel, Backoff with delay: $currentDelay seconds")
delay(currentDelay.toLong() * 1000)
}

View File

@ -180,7 +180,8 @@ class PushProxClient(private val pushProxConfig: PushProxConfig) {
ExponentialBackoff.runWithBackoff(
function = { doPoll(context) },
onException = { counters.pollError() }
onException = { counters.pollError() },
"pushprox"
)
Log.d(TAG, "PushProxClient main loop end")

View File

@ -29,7 +29,7 @@ private const val TAG: String = "REMOTE_WRITE_SENDER"
// for purposes of scraping metrics on device and back-filling them later using remote write
//
// Only timestamps of succesfull scrapes are stored
private class LastTimeRingBuffer(private val scrapeIntervalMs: Int) {
internal class LastTimeRingBuffer(private val scrapeIntervalMs: Int) {
private val buffer: Array<Long> = Array(hysteresisThreshold) { 0 }
private var firstIndex: Int = 0
@ -42,7 +42,7 @@ private class LastTimeRingBuffer(private val scrapeIntervalMs: Int) {
buffer[firstIndex] = timestamp
}
private fun getTimeByIndex(index: Int): Long {
fun getTimeByIndex(index: Int): Long {
if (index > hysteresisThreshold - 1) {
throw IllegalArgumentException("index cannot be bigger than hysteresisThreshold")
}
@ -111,7 +111,6 @@ class RemoteWriteSender(private val config: RemoteWriteConfiguration) {
Log.d(TAG, "Turning remote write on")
performScrapeAndSaveIt(channel)
delay(config.scrapeInterval * 1000L)
while (lastTimeRingBuffer.checkScrapeDidNotHappenHysteresis()) {
delay(config.scrapeInterval * 1000L)
@ -164,7 +163,7 @@ class RemoteWriteSender(private val config: RemoteWriteConfiguration) {
Log.d(TAG, "Exponential backoff to export remote write started")
ExponentialBackoff.runWithBackoff({
sendRequestToRemoteWrite(body, config.maxSamplesPerExport)
}, {}, false)
}, {}, "Remote Write", false)
Log.d(TAG, "Exponential backoff to export remote write finish")
}
lastTimeRemoteWriteSent = System.currentTimeMillis()

View File

@ -0,0 +1,14 @@
package com.birdthedeveloper.prometheus.android.prometheus.android.exporter.worker
import org.junit.Assert
import org.junit.Assert.*
import org.junit.Test
class LastTimeRingBufferTest {
@Test
fun setLastTime() {
Assert.assertEquals(true, true)
}
}