forked from Azure/azure-sdk-for-java
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement comparable on EventData (Azure#395)
- Loading branch information
Showing
4 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
azure-eventhubs/src/test/java/com/microsoft/azure/eventhubs/impl/EventDataOrderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (c) Microsoft. All rights reserved. | ||
* Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
*/ | ||
package com.microsoft.azure.eventhubs.impl; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
|
||
import com.microsoft.azure.eventhubs.EventData; | ||
import org.apache.qpid.proton.amqp.Symbol; | ||
import org.apache.qpid.proton.amqp.messaging.MessageAnnotations; | ||
import org.apache.qpid.proton.message.Message; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class EventDataOrderTest { | ||
|
||
private EventData constructMessage(long seqNumber) { | ||
HashMap<Symbol, Object> properties = new HashMap<>(); | ||
properties.put(AmqpConstants.SEQUENCE_NUMBER, seqNumber); | ||
|
||
Message message = Message.Factory.create(); | ||
|
||
message.setMessageAnnotations(new MessageAnnotations(properties)); | ||
|
||
return new EventDataImpl(message); | ||
} | ||
|
||
@Test | ||
public void eventDataEmptyByteArray() { | ||
ArrayList<EventData> messages = new ArrayList<>(); | ||
|
||
EventData first = constructMessage(19); | ||
EventData second = constructMessage(22); | ||
EventData third = constructMessage(25); | ||
EventData last = constructMessage(88); | ||
|
||
messages.add(second); | ||
messages.add(first); | ||
messages.add(last); | ||
messages.add(third); | ||
|
||
Collections.sort(messages); | ||
|
||
Assert.assertEquals(messages.get(0), first); | ||
Assert.assertEquals(messages.get(1), second); | ||
Assert.assertEquals(messages.get(2), third); | ||
Assert.assertEquals(messages.get(3), last); | ||
} | ||
} |