Skip to content

Commit d6ff228

Browse files
author
Quintin Willison
committed
Remove the unnecessary DeltaExtras constructor on MessageExtras.
1 parent 99e3407 commit d6ff228

3 files changed

Lines changed: 16 additions & 78 deletions

File tree

lib/src/main/java/io/ably/lib/types/MessageExtras.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ public MessageExtras(final JsonObject jsonObject) {
3636
this(jsonObject, null);
3737
}
3838

39-
/**
40-
* @since 1.2.0
41-
*/
42-
public MessageExtras(final DeltaExtras delta) {
43-
this(Serializer.wrapDelta(delta), delta);
44-
}
45-
4639
private MessageExtras(final JsonObject jsonObject, final DeltaExtras delta) {
4740
if (null == jsonObject) {
4841
throw new NullPointerException("jsonObject cannot be null.");

lib/src/test/java/io/ably/lib/test/realtime/RealtimeDeltaDecoderTest.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import java.util.Objects;
77

8+
import com.google.gson.JsonObject;
89
import org.junit.Rule;
910
import org.junit.Test;
1011
import org.junit.rules.Timeout;
@@ -133,19 +134,27 @@ public ITransport getTransport(ITransport.TransportParams transportParams, Conne
133134
* Special transport class that corrupts the order bookkeeping of delta messages to allow testing delta recovery.
134135
*/
135136
private static class OutOfOrderDeltasWebsocketTransportMock extends WebSocketTransport {
136-
137+
private static final String DELTA = "delta";
137138

138139
private OutOfOrderDeltasWebsocketTransportMock(TransportParams transportParams, ConnectionManager connectionManager) {
139140
super(transportParams, connectionManager);
140141
}
141142

142143
@Override
143-
protected void preProcessReceivedMessage(ProtocolMessage message) {
144-
if(message.action == ProtocolMessage.Action.message &&
145-
message.messages[0].extras != null &&
146-
message.messages[0].extras.getDelta() != null) {
147-
final String format = message.messages[0].extras.getDelta().getFormat();
148-
message.messages[0].extras = new MessageExtras(new DeltaExtras(format, ""));
144+
protected void preProcessReceivedMessage(ProtocolMessage protocolMessage) {
145+
if(protocolMessage.action == ProtocolMessage.Action.message) {
146+
for (final Message message : protocolMessage.messages) {
147+
final MessageExtras extras = message.extras;
148+
if (extras != null) {
149+
final JsonObject json = message.extras.asJsonObject();
150+
151+
if (json.has(DELTA)) {
152+
// This MessageExtras (json) has DeltaExtras.
153+
// Corrupt it by replacing the value at the from key with an empty string.
154+
json.getAsJsonObject(DELTA).addProperty("from", "");
155+
}
156+
}
157+
}
149158
}
150159
}
151160
}

lib/src/test/java/io/ably/lib/types/MessageExtrasTest.java

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -62,68 +62,4 @@ public void rawViaMessagePack() throws IOException {
6262
public void rawNullArgument() {
6363
new MessageExtras((JsonObject)null);
6464
}
65-
66-
/**
67-
* Construct an instance with DeltaExtras and validate that the
68-
* serialised JSON is as expected. Also validate that the DeltaExtras
69-
* retrieved is the same.
70-
*/
71-
@Test
72-
public void delta() {
73-
final DeltaExtras deltaExtrasA = new DeltaExtras("someFormat", "someSource");
74-
final DeltaExtras deltaExtrasB = new DeltaExtras("someFormat", "someOtherSource");
75-
76-
final MessageExtras messageExtras = new MessageExtras(deltaExtrasA);
77-
assertEquals(deltaExtrasA, messageExtras.getDelta());
78-
assertNotEquals(deltaExtrasB, messageExtras.getDelta());
79-
assertNotEquals(deltaExtrasB, deltaExtrasA);
80-
81-
final JsonObject expectedJsonElement = deltaExtrasJsonObject("someFormat", "someSource");
82-
83-
final MessageExtras.Serializer serializer = new MessageExtras.Serializer();
84-
final JsonElement serialised = serializer.serialize(messageExtras, null, null);
85-
86-
assertEquals(expectedJsonElement, serialised);
87-
}
88-
89-
/**
90-
* Construct an instance with DeltaExtras and validate that it can be encoded
91-
* to MessagePack and then decoded back again from MessagePack.
92-
*/
93-
@Test
94-
public void deltaViaMessagePack() throws IOException {
95-
final DeltaExtras deltaExtras = new DeltaExtras("tamrof", "morf");
96-
final MessageExtras messageExtras = new MessageExtras(deltaExtras);
97-
final JsonObject expectedMessageExtrasJsonObject = deltaExtrasJsonObject("tamrof", "morf");
98-
assertEquals(expectedMessageExtrasJsonObject, messageExtras.asJsonObject());
99-
100-
// Encode to MessagePack
101-
final ByteArrayOutputStream out = new ByteArrayOutputStream();
102-
final MessagePacker packer = Serialisation.msgpackPackerConfig.newPacker(out);
103-
messageExtras.write(packer);
104-
packer.flush();
105-
106-
// Decode from MessagePack
107-
System.out.println("len: " + out.toByteArray().length);
108-
MessageUnpacker unpacker = Serialisation.msgpackUnpackerConfig.newUnpacker(out.toByteArray());
109-
final MessageExtras unpacked = MessageExtras.read(unpacker);
110-
111-
assertEquals(messageExtras.getDelta(), unpacked.getDelta());
112-
assertEquals(messageExtras, unpacked);
113-
assertEquals(expectedMessageExtrasJsonObject, unpacked.asJsonObject());
114-
}
115-
116-
@Test(expected = NullPointerException.class)
117-
public void deltaNullArgument() {
118-
new MessageExtras((DeltaExtras)null);
119-
}
120-
121-
private static JsonObject deltaExtrasJsonObject(final String format, final String from) {
122-
final JsonObject deltaExtrasJsonElement = new JsonObject();
123-
deltaExtrasJsonElement.addProperty("format", format);
124-
deltaExtrasJsonElement.addProperty("from", from);
125-
final JsonObject jsonElement = new JsonObject();
126-
jsonElement.add("delta", deltaExtrasJsonElement);
127-
return jsonElement;
128-
}
12965
}

0 commit comments

Comments
 (0)