public CompletableFuture<Optional<MessageProtos.Envelope>> deleteMessageByDestinationAndGuid(
      final UUID destinationAccountUuid, final Device destinationDevice, final UUID messageUuid) {
    return Stream.of(convertPartitionKey(destinationAccountUuid, destinationDevice),
        convertPartitionKeyDeprecated(destinationAccountUuid, destinationDevice))
        .distinct()
        .map(pk -> deleteMessageByDestinationAndGuid(pk, messageUuid))
        // this combines the futures by producing a future that returns an arbitrary nonempty
        // result if there is one, which should be OK because only one of the keys
        // should produce a nonempty result for any given message uuid
        .reduce((f, g) -> f.thenCombine(g, (a, b) -> a.or(() -> b)))
        .get();
  }
@Test
  void testDeleteMessageByDestinationAndGuid() throws Exception {
    final UUID destinationUuid = UUID.randomUUID();
    final UUID secondDestinationUuid = UUID.randomUUID();
    final Device primary = DevicesHelper.createDevice((byte) 1);
    final Device device2 = DevicesHelper.createDevice((byte) 2);

    messagesDynamoDb.store(List.of(MESSAGE1), destinationUuid, primary);
    messagesDynamoDb.store(List.of(MESSAGE2), secondDestinationUuid, primary);
    messagesDynamoDb.store(List.of(MESSAGE3), destinationUuid, device2);

    assertThat(load(destinationUuid, primary, MessagesDynamoDb.RESULT_SET_CHUNK_SIZE)).isNotNull().hasSize(1)
        .element(0).isEqualTo(MESSAGE1);
    assertThat(load(destinationUuid, device2, MessagesDynamoDb.RESULT_SET_CHUNK_SIZE)).isNotNull()
        .hasSize(1)
        .element(0).isEqualTo(MESSAGE3);
    assertThat(load(secondDestinationUuid, primary, MessagesDynamoDb.RESULT_SET_CHUNK_SIZE)).isNotNull()
        .hasSize(1).element(0).isEqualTo(MESSAGE2);

    final Optional<MessageProtos.Envelope> deletedMessage = messagesDynamoDb.deleteMessageByDestinationAndGuid(
        secondDestinationUuid, primary,
        UUID.fromString(MESSAGE2.getServerGuid())).get(5, TimeUnit.SECONDS);

    assertThat(deletedMessage).isPresent();

    assertThat(load(destinationUuid, primary, MessagesDynamoDb.RESULT_SET_CHUNK_SIZE)).isNotNull().hasSize(1)
        .element(0).isEqualTo(MESSAGE1);
    assertThat(load(destinationUuid, device2, MessagesDynamoDb.RESULT_SET_CHUNK_SIZE)).isNotNull()
        .hasSize(1)
        .element(0).isEqualTo(MESSAGE3);
    assertThat(load(secondDestinationUuid, primary, MessagesDynamoDb.RESULT_SET_CHUNK_SIZE)).isNotNull()
        .isEmpty();

    final Optional<MessageProtos.Envelope> alreadyDeletedMessage = messagesDynamoDb.deleteMessageByDestinationAndGuid(
        secondDestinationUuid, primary,
        UUID.fromString(MESSAGE2.getServerGuid())).get(5, TimeUnit.SECONDS);

    assertThat(alreadyDeletedMessage).isNotPresent();

  }