From 0dd058d8cb84fc5b9faa4c9574306356bfd6ec83 Mon Sep 17 00:00:00 2001 From: SJ Date: Thu, 13 Dec 2018 18:09:56 -0800 Subject: [PATCH] Support IsPartitionEmpty property for PartitionRuntimeInformation (#399) --- .../eventhubs/PartitionRuntimeInformation.java | 9 ++++++++- .../azure/eventhubs/impl/ClientConstants.java | 1 + .../azure/eventhubs/impl/EventHubClientImpl.java | 15 ++++++++------- .../eventhubs/sendrecv/RequestResponseTest.java | 2 +- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/PartitionRuntimeInformation.java b/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/PartitionRuntimeInformation.java index 6d4695ee47bbe..c086f63ca8186 100644 --- a/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/PartitionRuntimeInformation.java +++ b/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/PartitionRuntimeInformation.java @@ -14,6 +14,7 @@ public final class PartitionRuntimeInformation { private final long lastEnqueuedSequenceNumber; private final String lastEnqueuedOffset; private final Instant lastEnqueuedTimeUtc; + private final boolean isEmpty; public PartitionRuntimeInformation( final String eventHubPath, @@ -21,7 +22,8 @@ public PartitionRuntimeInformation( final long beginSequenceNumber, final long lastEnqueuedSequenceNumber, final String lastEnqueuedOffset, - final Instant lastEnqueuedTimeUtc) { + final Instant lastEnqueuedTimeUtc, + final boolean isEmpty) { this.eventHubPath = eventHubPath; this.partitionId = partitionId; @@ -29,6 +31,7 @@ public PartitionRuntimeInformation( this.lastEnqueuedSequenceNumber = lastEnqueuedSequenceNumber; this.lastEnqueuedOffset = lastEnqueuedOffset; this.lastEnqueuedTimeUtc = lastEnqueuedTimeUtc; + this.isEmpty = isEmpty; } public String getEventHubPath() { @@ -54,4 +57,8 @@ public String getLastEnqueuedOffset() { public Instant getLastEnqueuedTimeUtc() { return this.lastEnqueuedTimeUtc; } + + public boolean getIsEmpty() { + return this.isEmpty; + } } diff --git a/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/ClientConstants.java b/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/ClientConstants.java index 507589cf6c79e..e827e5ca1fab6 100644 --- a/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/ClientConstants.java +++ b/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/ClientConstants.java @@ -66,6 +66,7 @@ public final class ClientConstants { public static final String MANAGEMENT_RESULT_LAST_ENQUEUED_SEQUENCE_NUMBER = "last_enqueued_sequence_number"; public static final String MANAGEMENT_RESULT_LAST_ENQUEUED_OFFSET = "last_enqueued_offset"; public static final String MANAGEMENT_RESULT_LAST_ENQUEUED_TIME_UTC = "last_enqueued_time_utc"; + public static final String MANAGEMENT_RESULT_PARTITION_IS_EMPTY = "is_partition_empty"; public static final String MANAGEMENT_STATUS_CODE_KEY = "status-code"; public static final String MANAGEMENT_STATUS_DESCRIPTION_KEY = "status-description"; public static final String MANAGEMENT_RESPONSE_ERROR_CONDITION = "error-condition"; diff --git a/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/EventHubClientImpl.java b/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/EventHubClientImpl.java index 5fbd6f62ed9e1..075dfdbca9b22 100644 --- a/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/EventHubClientImpl.java +++ b/azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/EventHubClientImpl.java @@ -281,15 +281,16 @@ public CompletableFuture getPartitionRuntimeInforma if (future1 == null) { future1 = managementWithRetry(request).thenComposeAsync(new Function, CompletableFuture>() { @Override - public CompletableFuture apply(Map rawdata) { + public CompletableFuture apply(Map rawData) { CompletableFuture future2 = new CompletableFuture(); future2.complete(new PartitionRuntimeInformation( - (String) rawdata.get(ClientConstants.MANAGEMENT_ENTITY_NAME_KEY), - (String) rawdata.get(ClientConstants.MANAGEMENT_PARTITION_NAME_KEY), - (long) rawdata.get(ClientConstants.MANAGEMENT_RESULT_BEGIN_SEQUENCE_NUMBER), - (long) rawdata.get(ClientConstants.MANAGEMENT_RESULT_LAST_ENQUEUED_SEQUENCE_NUMBER), - (String) rawdata.get(ClientConstants.MANAGEMENT_RESULT_LAST_ENQUEUED_OFFSET), - ((Date) rawdata.get(ClientConstants.MANAGEMENT_RESULT_LAST_ENQUEUED_TIME_UTC)).toInstant())); + (String) rawData.get(ClientConstants.MANAGEMENT_ENTITY_NAME_KEY), + (String) rawData.get(ClientConstants.MANAGEMENT_PARTITION_NAME_KEY), + (long) rawData.get(ClientConstants.MANAGEMENT_RESULT_BEGIN_SEQUENCE_NUMBER), + (long) rawData.get(ClientConstants.MANAGEMENT_RESULT_LAST_ENQUEUED_SEQUENCE_NUMBER), + (String) rawData.get(ClientConstants.MANAGEMENT_RESULT_LAST_ENQUEUED_OFFSET), + ((Date) rawData.get(ClientConstants.MANAGEMENT_RESULT_LAST_ENQUEUED_TIME_UTC)).toInstant(), + (boolean)rawData.get(ClientConstants.MANAGEMENT_RESULT_PARTITION_IS_EMPTY))); return future2; } }, this.executor); diff --git a/azure-eventhubs/src/test/java/com/microsoft/azure/eventhubs/sendrecv/RequestResponseTest.java b/azure-eventhubs/src/test/java/com/microsoft/azure/eventhubs/sendrecv/RequestResponseTest.java index b2712a6a92874..bd29b39907b64 100644 --- a/azure-eventhubs/src/test/java/com/microsoft/azure/eventhubs/sendrecv/RequestResponseTest.java +++ b/azure-eventhubs/src/test/java/com/microsoft/azure/eventhubs/sendrecv/RequestResponseTest.java @@ -204,7 +204,7 @@ public void testGetRuntimeInfos(ConnectionStringBuilder connectionString) throws Assert.assertNotNull(ehInfo); Assert.assertTrue(connectionString.getEventHubName().equalsIgnoreCase(ehInfo.getPath())); Assert.assertNotNull(ehInfo.getCreatedAt()); // creation time could be almost anything, can't really check value - Assert.assertTrue(ehInfo.getPartitionCount() >= 2); // max legal partition count is variable but 2 is hard minimum + Assert.assertTrue(ehInfo.getPartitionCount() >= 1); // max legal partition count is variable but 2 is hard minimum Assert.assertEquals(ehInfo.getPartitionIds().length, ehInfo.getPartitionCount()); /* System.out.println("Event hub name: " + ehInfo.getPath());