-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PartialSerialisedMessage test. (#27452)
* Test deserialise. * Add tests. * Simplify and fix tests. * Format. * Adds tests for deserializeAirbyteMessage * Adds tests for deserializeAirbyteMessage with bad data * Cleans up deserializeAirbyteMessage and throws Exception when invalid message * More code cleanup --------- Co-authored-by: ryankfu <ryan.fu@airbyte.io>
- Loading branch information
Showing
5 changed files
with
173 additions
and
73 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
66 changes: 66 additions & 0 deletions
66
...va/src/test/java/io/airbyte/integrations/destination_async/PartialAirbyteMessageTest.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,66 @@ | ||
/* | ||
* Copyright (c) 2023 Airbyte, Inc., all rights reserved. | ||
*/ | ||
|
||
package io.airbyte.integrations.destination_async; | ||
|
||
import io.airbyte.commons.json.Jsons; | ||
import io.airbyte.integrations.destination_async.partial_messages.PartialAirbyteMessage; | ||
import io.airbyte.protocol.models.AirbyteStateMessage; | ||
import io.airbyte.protocol.models.AirbyteStreamState; | ||
import io.airbyte.protocol.models.StreamDescriptor; | ||
import io.airbyte.protocol.models.v0.AirbyteMessage; | ||
import io.airbyte.protocol.models.v0.AirbyteRecordMessage; | ||
import java.time.Instant; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class PartialAirbyteMessageTest { | ||
|
||
@Test | ||
void testDeserializeRecord() { | ||
final long emittedAt = Instant.now().toEpochMilli(); | ||
final var serializedRec = Jsons.serialize(new AirbyteMessage() | ||
.withType(AirbyteMessage.Type.RECORD) | ||
.withRecord(new AirbyteRecordMessage() | ||
.withStream("users") | ||
.withNamespace("public") | ||
.withEmittedAt(emittedAt) | ||
.withData(Jsons.jsonNode("data")))); | ||
|
||
final var rec = Jsons.tryDeserialize(serializedRec, PartialAirbyteMessage.class).get(); | ||
Assertions.assertEquals(AirbyteMessage.Type.RECORD, rec.getType()); | ||
Assertions.assertEquals("users", rec.getRecord().getStream()); | ||
Assertions.assertEquals("public", rec.getRecord().getNamespace()); | ||
Assertions.assertEquals("\"data\"", rec.getRecord().getData().toString()); | ||
Assertions.assertEquals(emittedAt, rec.getRecord().getEmittedAt()); | ||
} | ||
|
||
@Test | ||
void testDeserializeState() { | ||
final var serializedState = Jsons.serialize(new io.airbyte.protocol.models.AirbyteMessage() | ||
.withType(io.airbyte.protocol.models.AirbyteMessage.Type.STATE) | ||
.withState(new AirbyteStateMessage().withStream( | ||
new AirbyteStreamState().withStreamDescriptor( | ||
new StreamDescriptor().withName("user").withNamespace("public")) | ||
.withStreamState(Jsons.jsonNode("data"))) | ||
.withType(AirbyteStateMessage.AirbyteStateType.STREAM))); | ||
|
||
final var rec = Jsons.tryDeserialize(serializedState, PartialAirbyteMessage.class).get(); | ||
Assertions.assertEquals(AirbyteMessage.Type.STATE, rec.getType()); | ||
|
||
final var streamDesc = rec.getState().getStream().getStreamDescriptor(); | ||
Assertions.assertEquals("user", streamDesc.getName()); | ||
Assertions.assertEquals("public", streamDesc.getNamespace()); | ||
Assertions.assertEquals(io.airbyte.protocol.models.v0.AirbyteStateMessage.AirbyteStateType.STREAM, rec.getState().getType()); | ||
} | ||
|
||
@Test | ||
void testGarbage() { | ||
final var badSerialization = "messed up data"; | ||
|
||
final var rec = Jsons.tryDeserialize(badSerialization, PartialAirbyteMessage.class); | ||
Assertions.assertTrue(rec.isEmpty()); | ||
} | ||
|
||
} |
Oops, something went wrong.