Skip to content

Commit 100f047

Browse files
Make EventData.SystemProperties completely public (#435)
Porting testability changes from .NET Core to Java: provide full access to EventData's SystemProperties so that a complete EventData can be fabricated in tests.
1 parent 0e52fd7 commit 100f047

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/EventData.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,13 +145,21 @@ static EventData create(final ByteBuffer buffer) {
145145
* @see SystemProperties#getEnqueuedTime
146146
*/
147147
SystemProperties getSystemProperties();
148+
void setSystemProperties(SystemProperties props);
148149

149-
class SystemProperties extends HashMap<String, Object> {
150+
public class SystemProperties extends HashMap<String, Object> {
150151
private static final long serialVersionUID = -2827050124966993723L;
151152

152153
public SystemProperties(final HashMap<String, Object> map) {
153154
super(Collections.unmodifiableMap(map));
154155
}
156+
157+
public SystemProperties(final long sequenceNumber, final Instant enqueuedTimeUtc, final String offset, final String partitionKey) {
158+
this.put(AmqpConstants.SEQUENCE_NUMBER_ANNOTATION_NAME, sequenceNumber);
159+
this.put(AmqpConstants.ENQUEUED_TIME_UTC_ANNOTATION_NAME, new Date(enqueuedTimeUtc.toEpochMilli()));
160+
this.put(AmqpConstants.OFFSET_ANNOTATION_NAME, offset);
161+
this.put(AmqpConstants.PARTITION_KEY_ANNOTATION_NAME, partitionKey);
162+
}
155163

156164
public String getOffset() {
157165
return this.getSystemProperty(AmqpConstants.OFFSET_ANNOTATION_NAME);

azure-eventhubs/src/main/java/com/microsoft/azure/eventhubs/impl/EventDataImpl.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,10 @@ public SystemProperties getSystemProperties() {
146146
return this.systemProperties;
147147
}
148148

149+
public void setSystemProperties(EventData.SystemProperties props) {
150+
this.systemProperties = props;
151+
}
152+
149153
// This is intended to be used while sending EventData - so EventData.SystemProperties will not be copied over to the AmqpMessage
150154
Message toAmqpMessage() {
151155
final Message amqpMessage = Proton.message();

0 commit comments

Comments
 (0)