diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/push/ProvisioningManager.java b/service/src/main/java/org/whispersystems/textsecuregcm/push/ProvisioningManager.java index daa5c445b..89a79ad4a 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/push/ProvisioningManager.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/push/ProvisioningManager.java @@ -7,7 +7,6 @@ package org.whispersystems.textsecuregcm.push; import static org.whispersystems.textsecuregcm.metrics.MetricsUtil.name; -import com.google.common.annotations.VisibleForTesting; import com.google.protobuf.ByteString; import com.google.protobuf.InvalidProtocolBufferException; import io.dropwizard.lifecycle.Managed; @@ -67,14 +66,12 @@ public class ProvisioningManager extends RedisPubSubAdapter impl public void addListener(final String address, final Consumer listener) { listenersByProvisioningAddress.put(address, listener); - pubSubConnection.usePubSubConnection(connection -> connection.sync().subscribe( - getPrefixedChannel(address), getUnprefixedChannel(address))); + pubSubConnection.usePubSubConnection(connection -> connection.sync().subscribe(getChannel(address))); } public void removeListener(final String address) { RedisOperation.unchecked(() -> - pubSubConnection.usePubSubConnection(connection -> connection.sync().unsubscribe( - getPrefixedChannel(address), getUnprefixedChannel(address)))); + pubSubConnection.usePubSubConnection(connection -> connection.sync().unsubscribe(getChannel(address)))); listenersByProvisioningAddress.remove(address); } @@ -87,7 +84,7 @@ public class ProvisioningManager extends RedisPubSubAdapter impl final boolean receiverPresent = ResilienceUtil.getGeneralRedisRetry(RETRY_NAME) .executeSupplier(() -> pubSubClient.withBinaryConnection(connection -> - connection.sync().publish(getPrefixedChannel(address), pubSubMessage.toByteArray()) > 0)); + connection.sync().publish(getChannel(address), pubSubMessage.toByteArray()) > 0)); Metrics.counter(SEND_PROVISIONING_MESSAGE_COUNTER_NAME, "online", String.valueOf(receiverPresent)).increment(); @@ -122,19 +119,11 @@ public class ProvisioningManager extends RedisPubSubAdapter impl listenersByProvisioningAddress.remove(getAddress(channel)); } - @VisibleForTesting - static byte[] getPrefixedChannel(final String address) { + private static byte[] getChannel(final String address) { return (CHANNEL_PREFIX + address).getBytes(StandardCharsets.UTF_8); } - @VisibleForTesting - static byte[] getUnprefixedChannel(final String address) { - return address.getBytes(StandardCharsets.UTF_8); - } - private static String getAddress(final byte[] channel) { - final String channelName = new String(channel, StandardCharsets.UTF_8); - - return channelName.startsWith(CHANNEL_PREFIX) ? channelName.substring(CHANNEL_PREFIX.length()) : channelName; + return new String(channel, StandardCharsets.UTF_8).substring(CHANNEL_PREFIX.length()); } } diff --git a/service/src/test/java/org/whispersystems/textsecuregcm/push/ProvisioningManagerTest.java b/service/src/test/java/org/whispersystems/textsecuregcm/push/ProvisioningManagerTest.java index 65bed7769..53faa33f7 100644 --- a/service/src/test/java/org/whispersystems/textsecuregcm/push/ProvisioningManagerTest.java +++ b/service/src/test/java/org/whispersystems/textsecuregcm/push/ProvisioningManagerTest.java @@ -14,8 +14,6 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; import org.mockito.ArgumentCaptor; import org.whispersystems.textsecuregcm.redis.RedisServerExtension; import org.whispersystems.textsecuregcm.storage.PubSubProtos; @@ -74,36 +72,4 @@ class ProvisioningManagerTest { // Make sure that we give the message enough time to show up (if it was going to) before declaring victory verify(subscribedConsumer, after(PUBSUB_TIMEOUT_MILLIS).never()).accept(any()); } - - @ParameterizedTest - @ValueSource(booleans = {true, false}) - void receiveProvisioningMessageChannelMigration(final boolean prefixedChannel) { - final String provisioningAddress = UUID.randomUUID().toString(); - - final byte[] channel = prefixedChannel - ? ProvisioningManager.getPrefixedChannel(provisioningAddress) - : ProvisioningManager.getUnprefixedChannel(provisioningAddress); - - final byte[] content = TestRandomUtil.nextBytes(16); - - @SuppressWarnings("unchecked") final Consumer subscribedConsumer = mock(Consumer.class); - - provisioningManager.addListener(provisioningAddress, subscribedConsumer); - - final PubSubProtos.PubSubMessage pubSubMessage = PubSubProtos.PubSubMessage.newBuilder() - .setType(PubSubProtos.PubSubMessage.Type.DELIVER) - .setContent(ByteString.copyFrom(content)) - .build(); - - REDIS_EXTENSION.getRedisClient().useBinaryConnection(connection -> - connection.sync().publish(channel, pubSubMessage.toByteArray())); - - final ArgumentCaptor messageCaptor = - ArgumentCaptor.forClass(PubSubProtos.PubSubMessage.class); - - verify(subscribedConsumer, timeout(PUBSUB_TIMEOUT_MILLIS)).accept(messageCaptor.capture()); - - assertEquals(PubSubProtos.PubSubMessage.Type.DELIVER, messageCaptor.getValue().getType()); - assertEquals(ByteString.copyFrom(content), messageCaptor.getValue().getContent()); - } }