Skip to content

Commit

Permalink
Merge changes from master (#282)
Browse files Browse the repository at this point in the history
* Enable retryConfiguration with exponential strategy (#279)

for subscribe by default.

---------

Co-authored-by: marcin-cebo <[email protected]>
  • Loading branch information
wkal-pubnub and marcin-cebo authored Sep 20, 2024
1 parent 88e29b1 commit 210adc1
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,11 @@ interface PNConfiguration : com.pubnub.api.v2.PNConfiguration {

/**
* Retry configuration for requests.
* Defaults to [RetryConfiguration.None].
* Defaults to [RetryConfiguration.Exponential] enabled only for subscription endpoint (other endpoints are excluded).
*
* Use [RetryConfiguration.Linear] to set retry with linear delay interval
* Use [RetryConfiguration.Exponential] to set retry with exponential delay interval
* Delay will valy from provided value by random value.
* Delay will vary from provided value by random value.
*/
val retryConfiguration: RetryConfiguration

Expand Down Expand Up @@ -507,11 +507,11 @@ interface PNConfiguration : com.pubnub.api.v2.PNConfiguration {

/**
* Retry configuration for requests.
* Defaults to [RetryConfiguration.None].
* Defaults to [RetryConfiguration.Exponential] enabled only for subscription endpoint (other endpoints are excluded).
*
* Use [RetryConfiguration.Linear] to set retry with linear delay interval
* Use [RetryConfiguration.Exponential] to set retry with exponential delay interval
* Delay will valy from provided value by random value.
* Delay will vary from provided value by random value.
*/
override fun retryConfiguration(retryConfiguration: RetryConfiguration): Builder

Expand Down Expand Up @@ -549,11 +549,11 @@ interface PNConfigurationOverride : com.pubnub.api.v2.PNConfigurationOverride {

/**
* Retry configuration for requests.
* Defaults to [RetryConfiguration.None].
* Defaults to [RetryConfiguration.Exponential] enabled only for subscription endpoint (other endpoints are excluded).
*
* Use [RetryConfiguration.Linear] to set retry with linear delay interval
* Use [RetryConfiguration.Exponential] to set retry with exponential delay interval
* Delay will valy from provided value by random value.
* Delay will vary from provided value by random value.
*/
fun retryConfiguration(retryConfiguration: RetryConfiguration): Builder

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ public void canCreateRetryConfigurationsWithDifferentParameters() {
int maxRetryNumber = 2;
List<RetryableEndpointGroup> excludedOperations = new ArrayList<>();

RetryConfiguration linearRetryConfigurationWithNoParams = new RetryConfiguration.Linear();
RetryConfiguration noneRetryConfiguration = RetryConfiguration.None.INSTANCE;

RetryConfiguration linearRetryConfigurationWithNoParamsa = new RetryConfiguration.Linear();
RetryConfiguration linearRetryConfigurationWithDelay = new RetryConfiguration.Linear(delayInSec);
RetryConfiguration linearRetryConfigurationWithDelayAndMaxRetry = new RetryConfiguration.Linear(delayInSec, maxRetryNumber);
RetryConfiguration linearRetryConfigurationWithAllParams = new RetryConfiguration.Linear(delayInSec, maxRetryNumber, excludedOperations);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,8 @@ private com.pubnub.api.java.PubNub adminPubNub() {
return com.pubnub.api.java.PubNub.create(pnConfiguration.build());
}

@Ignore("This test should be fixed")// To SubscribeEffectInvocation.EmitStatus in is SubscribeEvent.HandshakeFailure add affectedChannels and affectedChannelGroups
@Test
@Ignore
public void alwaysContinueSubscriptionToChannelGroupIfNoActionTaken() throws PubNubException, InterruptedException {
final String channelGroup = "chg-1-" + randomId();

Expand All @@ -224,8 +224,8 @@ public void alwaysContinueSubscriptionToChannelGroupIfNoActionTaken() throws Pub
}


@Ignore("This test should be fixed")// 1. To SubscribeEffectInvocation.EmitStatus in is SubscribeEvent.HandshakeFailure add affectedChannels and affectedChannelGroups
@Test
@Ignore
public void alwaysContinueSubscriptionIfNoActionTaken() throws InterruptedException {
final String channel = "ch-" + randomId();

Expand All @@ -239,7 +239,7 @@ public void alwaysContinueSubscriptionIfNoActionTaken() throws InterruptedExcept
&& collectedStatus.getPnStatus().getException().getAffectedChannels().contains(channel))
.count();

assertThat(countAccessDenied, greaterThan(1L));
assertThat(countAccessDenied, greaterThan(1L)); //Change this condition to equalTo(1L)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.pubnub.api.java.callbacks.SubscribeCallback;
import com.pubnub.api.java.v2.PNConfiguration;
import com.pubnub.api.models.consumer.PNStatus;
import com.pubnub.api.retry.RetryConfiguration;
import okhttp3.logging.HttpLoggingInterceptor;
import org.aeonbits.owner.ConfigFactory;
import org.awaitility.Awaitility;
Expand Down Expand Up @@ -146,6 +147,7 @@ private PNConfiguration getBasicPnConfiguration(@Nullable Consumer<PNConfigurati
} catch (PubNubException e) {
throw new RuntimeException(e);
}
pnConfiguration.retryConfiguration(RetryConfiguration.None.INSTANCE);
pnConfiguration.logVerbosity(PNLogVerbosity.NONE);
pnConfiguration.httpLoggingInterceptor(createInterceptor());
if (action != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.pubnub.api.enums.PNLogVerbosity
import com.pubnub.api.java.v2.PNConfiguration
import com.pubnub.api.java.v2.PNConfigurationOverride
import com.pubnub.api.retry.RetryConfiguration
import com.pubnub.api.retry.RetryableEndpointGroup
import okhttp3.Authenticator
import okhttp3.CertificatePinner
import okhttp3.ConnectionSpec
Expand Down Expand Up @@ -55,7 +56,19 @@ class PNConfigurationImpl(
override val dedupOnSubscribe: Boolean = false,
override val maximumMessagesCacheSize: Int = DEFAULT_DEDUPE_SIZE,
override val pnsdkSuffixes: Map<String, String> = emptyMap(),
override val retryConfiguration: RetryConfiguration = RetryConfiguration.None,
override val retryConfiguration: RetryConfiguration = RetryConfiguration.Exponential(
excludedOperations = listOf(
RetryableEndpointGroup.PUBLISH,
RetryableEndpointGroup.PRESENCE,
RetryableEndpointGroup.FILE_PERSISTENCE,
RetryableEndpointGroup.MESSAGE_PERSISTENCE,
RetryableEndpointGroup.CHANNEL_GROUP,
RetryableEndpointGroup.PUSH_NOTIFICATION,
RetryableEndpointGroup.APP_CONTEXT,
RetryableEndpointGroup.MESSAGE_REACTION,
RetryableEndpointGroup.ACCESS_MANAGER,
)
),
override val managePresenceListManually: Boolean = false,
) : PNConfiguration {
companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,37 @@ sealed class RetryConfiguration {

const val MAX_RETRIES = 6
}

override fun equals(other: Any?): Boolean {
if (this === other) {
return true
}
if (other !is Exponential) {
return false
}

if (minDelayInSec != other.minDelayInSec) {
return false
}
if (maxDelayInSec != other.maxDelayInSec) {
return false
}
if (maxRetryNumber != other.maxRetryNumber) {
return false
}
if (excludedOperations != other.excludedOperations) {
return false
}

return true
}

override fun hashCode(): Int {
var result = minDelayInSec.hashCode()
result = 31 * result + maxDelayInSec.hashCode()
result = 31 * result + maxRetryNumber
result = 31 * result + excludedOperations.hashCode()
return result
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ actual interface PNConfiguration {

/**
* Retry configuration for requests.
* Defaults to [RetryConfiguration.None].
* Defaults to [RetryConfiguration.Exponential] enabled only for subscription endpoint (other endpoints are excluded).
*
* Use [RetryConfiguration.Linear] to set retry with linear delay interval
* Use [RetryConfiguration.Exponential] to set retry with exponential delay interval
* Delay will valy from provided value by random value.
* Delay will vary from provided value by random value.
*/
val retryConfiguration: RetryConfiguration

Expand Down Expand Up @@ -554,7 +554,7 @@ actual interface PNConfiguration {

/**
* Retry configuration for requests.
* Defaults to [RetryConfiguration.None].
* Defaults to [RetryConfiguration.Exponential] enabled only for subscription endpoint (other endpoints are excluded).
*
* Use [RetryConfiguration.Linear] to set retry with linear delay intervar
* Use [RetryConfiguration.Exponential] to set retry with exponential delay interval
Expand Down Expand Up @@ -609,11 +609,11 @@ interface PNConfigurationOverride {

/**
* Retry configuration for requests.
* Defaults to [RetryConfiguration.None].
* Defaults to [RetryConfiguration.Exponential] enabled only for subscription endpoint (other endpoints are excluded).
*
* Use [RetryConfiguration.Linear] to set retry with linear delay interval
* Use [RetryConfiguration.Exponential] to set retry with exponential delay interval
* Delay will valy from provided value by random value.
* Delay will vary from provided value by random value.
*/
var retryConfiguration: RetryConfiguration

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.pubnub.api.integration
import com.pubnub.api.PubNub
import com.pubnub.api.UserId
import com.pubnub.api.enums.PNLogVerbosity
import com.pubnub.api.retry.RetryConfiguration
import com.pubnub.api.v2.PNConfiguration
import com.pubnub.test.CommonUtils.createInterceptor
import com.pubnub.test.Keys
Expand Down Expand Up @@ -92,6 +93,7 @@ abstract class BaseIntegrationTest {
clientConfig.publishKey = Keys.pamPubKey
clientConfig.authKey = provideAuthKey()!!
}
clientConfig.retryConfiguration = RetryConfiguration.None
clientConfig.logVerbosity = PNLogVerbosity.NONE
clientConfig.httpLoggingInterceptor = createInterceptor(logger)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import com.pubnub.api.PubNub
import com.pubnub.api.callbacks.SubscribeCallback
import com.pubnub.api.models.consumer.PNStatus
import com.pubnub.api.models.consumer.objects.PNMembershipKey
import com.pubnub.api.models.consumer.objects.PNPage
import com.pubnub.api.models.consumer.objects.PNSortKey
import com.pubnub.api.models.consumer.objects.channel.PNChannelMetadata
import com.pubnub.api.models.consumer.objects.member.PNMember
import com.pubnub.api.models.consumer.objects.member.PNUUIDDetailsLevel
import com.pubnub.api.models.consumer.objects.membership.PNChannelDetailsLevel
import com.pubnub.api.models.consumer.objects.membership.PNChannelMembership
import com.pubnub.api.models.consumer.objects.uuid.PNUUIDMetadata
import com.pubnub.api.models.consumer.objects.uuid.PNUUIDMetadataArrayResult
import com.pubnub.api.models.consumer.pubsub.objects.PNObjectEventResult
import com.pubnub.api.utils.PatchValue
import com.pubnub.test.CommonUtils.randomValue
Expand Down Expand Up @@ -58,6 +60,9 @@ class ObjectsIntegrationTest : BaseIntegrationTest() {

@Test
fun setGetAndRemoveUUIDMetadata() {
// maintenance task: remove all UserMetadata
// removeAllUserMetadataWithPaging() // this is not finished yet

val setResult =
pubnub.setUUIDMetadata(
uuid = testUuid,
Expand Down Expand Up @@ -403,4 +408,19 @@ class ObjectsIntegrationTest : BaseIntegrationTest() {
status = null,
)
}

fun removeAllUserMetadataWithPaging() { // should be fixed
var hasMore = true
var page: PNPage? = null
while (hasMore) {
println("-=page")
val allMetadataPage: PNUUIDMetadataArrayResult = pubnub.getAllUUIDMetadata(page = page).sync()

allMetadataPage.data.forEach { pnUUIDMetadata: PNUUIDMetadata ->
pubnub.removeUUIDMetadata(uuid = pnUUIDMetadata.id).sync()
}
page = allMetadataPage.next
hasMore = page != null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.pubnub.api.crypto.CryptoModule
import com.pubnub.api.enums.PNHeartbeatNotificationOptions
import com.pubnub.api.enums.PNLogVerbosity
import com.pubnub.api.retry.RetryConfiguration
import com.pubnub.api.retry.RetryableEndpointGroup
import com.pubnub.api.v2.PNConfiguration
import com.pubnub.api.v2.PNConfigurationOverride
import okhttp3.Authenticator
Expand Down Expand Up @@ -55,7 +56,19 @@ class PNConfigurationImpl(
override val dedupOnSubscribe: Boolean = false,
override val maximumMessagesCacheSize: Int = DEFAULT_DEDUPE_SIZE,
override val pnsdkSuffixes: Map<String, String> = emptyMap(),
override val retryConfiguration: RetryConfiguration = RetryConfiguration.None,
override val retryConfiguration: RetryConfiguration = RetryConfiguration.Exponential(
excludedOperations = listOf(
RetryableEndpointGroup.PUBLISH,
RetryableEndpointGroup.PRESENCE,
RetryableEndpointGroup.FILE_PERSISTENCE,
RetryableEndpointGroup.MESSAGE_PERSISTENCE,
RetryableEndpointGroup.CHANNEL_GROUP,
RetryableEndpointGroup.PUSH_NOTIFICATION,
RetryableEndpointGroup.APP_CONTEXT,
RetryableEndpointGroup.MESSAGE_REACTION,
RetryableEndpointGroup.ACCESS_MANAGER,
)
),
override val managePresenceListManually: Boolean = false,
) : PNConfiguration, PNConfigurationOverride {
companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig
import com.pubnub.api.UserId
import com.pubnub.api.enums.PNLogVerbosity
import com.pubnub.api.retry.RetryConfiguration
import com.pubnub.api.v2.PNConfiguration
import com.pubnub.internal.PubNubImpl
import com.pubnub.test.CommonUtils.defaultListenDuration
Expand Down Expand Up @@ -64,6 +65,7 @@ abstract class BaseTest {
origin = wireMockServer.baseUrl().toHttpUrlOrNull()!!.run { "$host:$port" }
secure = false
logVerbosity = PNLogVerbosity.BODY
retryConfiguration = RetryConfiguration.None
}

fun clearConfiguration() {
Expand Down

0 comments on commit 210adc1

Please sign in to comment.