Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into kmp-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
wkal-pubnub committed Sep 20, 2024
2 parents 88e29b1 + 195c321 commit 05232ae
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 15 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,6 +203,7 @@ 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 {
Expand All @@ -224,6 +225,7 @@ 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 {
Expand All @@ -239,7 +241,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

0 comments on commit 05232ae

Please sign in to comment.