-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Changed statement from UPDATE to UPSERT
Changed default retry strategy with dynamic delay Added unique record identifier to retry records
- Loading branch information
Showing
9 changed files
with
84 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.1-bin.zip | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/com/stroiker/distributed/deduplicator/Utils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.stroiker.distributed.deduplicator | ||
|
||
import com.datastax.oss.driver.api.core.ConsistencyLevel | ||
import com.datastax.oss.driver.api.core.CqlSession | ||
import com.datastax.oss.driver.api.core.DefaultConsistencyLevel | ||
import com.datastax.oss.driver.api.core.config.DefaultDriverOption | ||
import java.time.Duration | ||
|
||
object Utils { | ||
internal fun CqlSession.getConsistencyLevel(profileName: String): ConsistencyLevel = | ||
DefaultConsistencyLevel.valueOf( | ||
context.configLoader.initialConfig.getProfile(profileName) | ||
.getString(DefaultDriverOption.REQUEST_CONSISTENCY) | ||
) | ||
|
||
internal fun CqlSession.getRequestTimeout(profileName: String): Duration = | ||
context.configLoader.initialConfig.getProfile(profileName).getDuration(DefaultDriverOption.REQUEST_TIMEOUT) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 4 additions & 13 deletions
17
.../com/stroiker/distributed/deduplicator/strategy/impl/ExponentialDelayRetryStrategyTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,34 @@ | ||
package com.stroiker.distributed.deduplicator.strategy.impl | ||
|
||
import com.datastax.oss.driver.shaded.guava.common.base.Stopwatch | ||
import com.stroiker.distributed.deduplicator.exception.RetriesExceededException | ||
import com.stroiker.distributed.deduplicator.exception.RetryException | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import org.junitpioneer.jupiter.RetryingTest | ||
import java.time.Duration | ||
import java.util.concurrent.TimeUnit.MILLISECONDS | ||
|
||
class ExponentialDelayRetryStrategyTest { | ||
|
||
private val strategy = ExponentialDelayRetryStrategy(3, Duration.ofMillis(10)) | ||
|
||
@RetryingTest(maxAttempts = 5, name = "should retries 0 times") | ||
@Test | ||
fun `should retries 0 times`() { | ||
var counter = 0 | ||
val stopwatch = Stopwatch.createStarted() | ||
strategy.retry { counter++ } | ||
assertTrue(stopwatch.elapsed(MILLISECONDS) in 0..9) | ||
assertEquals(1, counter) | ||
} | ||
|
||
@RetryingTest(maxAttempts = 5, name = "should retries 0 times with other error") | ||
@Test | ||
fun `should retries 0 times with other error`() { | ||
var counter = 0 | ||
val stopwatch = Stopwatch.createStarted() | ||
assertThrows<RuntimeException> { strategy.retry { counter++; throw RuntimeException() } } | ||
assertTrue(stopwatch.elapsed(MILLISECONDS) in 0..9) | ||
assertEquals(1, counter) | ||
} | ||
|
||
@RetryingTest(maxAttempts = 5, name = "should retries 3 times with retry error") | ||
@Test | ||
fun `should retries 3 times with retry error`() { | ||
var counter = 0 | ||
val stopwatch = Stopwatch.createStarted() | ||
assertThrows<RetriesExceededException> { strategy.retry { counter++; throw RetryException("", "") } } | ||
assertTrue(stopwatch.elapsed(MILLISECONDS) in 300..320) | ||
assertEquals(4, counter) | ||
} | ||
} |
19 changes: 5 additions & 14 deletions
19
...kotlin/com/stroiker/distributed/deduplicator/strategy/impl/FixedDelayRetryStrategyTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,34 @@ | ||
package com.stroiker.distributed.deduplicator.strategy.impl | ||
|
||
import com.datastax.oss.driver.shaded.guava.common.base.Stopwatch | ||
import com.stroiker.distributed.deduplicator.exception.RetriesExceededException | ||
import com.stroiker.distributed.deduplicator.exception.RetryException | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertTrue | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import org.junitpioneer.jupiter.RetryingTest | ||
import java.time.Duration | ||
import java.util.concurrent.TimeUnit.MILLISECONDS | ||
|
||
class FixedDelayRetryStrategyTest { | ||
|
||
private val strategy = FixedDelayRetryStrategy(3, Duration.ofMillis(10)) | ||
private val strategy = FixedDelayRetryStrategy(3, Duration.ofMillis(1000)) | ||
|
||
@RetryingTest(maxAttempts = 5, name = "should retries 0 times") | ||
@Test | ||
fun `should retries 0 times`() { | ||
var counter = 0 | ||
val stopwatch = Stopwatch.createStarted() | ||
strategy.retry { counter++ } | ||
assertTrue(stopwatch.elapsed(MILLISECONDS) in 0..9) | ||
assertEquals(1, counter) | ||
} | ||
|
||
@RetryingTest(maxAttempts = 5, name = "should retries 0 times with other error") | ||
@Test | ||
fun `should retries 0 times with other error`() { | ||
var counter = 0 | ||
val stopwatch = Stopwatch.createStarted() | ||
assertThrows<RuntimeException> { strategy.retry { counter++; throw RuntimeException() } } | ||
assertTrue(stopwatch.elapsed(MILLISECONDS) in 0..9) | ||
assertEquals(1, counter) | ||
} | ||
|
||
@RetryingTest(maxAttempts = 5, name = "should retries 3 times with retry error") | ||
@Test | ||
fun `should retries 3 times with retry error`() { | ||
var counter = 0 | ||
val stopwatch = Stopwatch.createStarted() | ||
assertThrows<RetriesExceededException> { strategy.retry { counter++; throw RetryException("", "") } } | ||
assertTrue(stopwatch.elapsed(MILLISECONDS) in 30..39) | ||
assertEquals(4, counter) | ||
} | ||
} |