@Test public void nonSerializableObject() { SerializingConverter toBytes = new SerializingConverter(); try { toBytes.convert(new Object()); fail("Expected IllegalArgumentException"); } catch (SerializationFailedException e) { assertNotNull(e.getCause()); assertTrue(e.getCause() instanceof IllegalArgumentException); } }
@Test public void serializeAndDeserializeString() { SerializingConverter toBytes = new SerializingConverter(); byte[] bytes = toBytes.convert("Testing"); DeserializingConverter fromBytes = new DeserializingConverter(); assertEquals("Testing", fromBytes.convert(bytes)); }
@Test public void nonSerializableField() { SerializingConverter toBytes = new SerializingConverter(); try { toBytes.convert(new UnSerializable()); fail("Expected SerializationFailureException"); } catch (SerializationFailedException e) { assertNotNull(e.getCause()); assertTrue(e.getCause() instanceof NotSerializableException); } }
@Override @SuppressWarnings("unchecked") public <T> Message<T> addMessage(final Message<T> message) { UUID id = message.getHeaders().getId(); Assert.notNull(id, "Cannot store messages without an ID header"); final String messageId = getKey(id); final byte[] messageBytes = this.serializer.convert(message); if (logger.isDebugEnabled()) { logger.debug("Inserting message with id key=" + messageId); } try { this.jdbcTemplate.update(getQuery(Query.CREATE_MESSAGE), ps -> { ps.setString(1, messageId); ps.setString(2, this.region); ps.setTimestamp(3, new Timestamp(System.currentTimeMillis())); this.lobHandler.getLobCreator().setBlobAsBytes(ps, 4, messageBytes); }); } catch (DuplicateKeyException e) { if (logger.isDebugEnabled()) { logger.debug("The Message with id [" + id + "] already exists.\n" + "Ignoring INSERT and SELECT existing..."); } return (Message<T>) getMessage(id); } return message; }
byte[] messageBytes = this.serializer.convert(requestMessage); this.lobHandler.getLobCreator().setBlobAsBytes(preparedStatement, 6, messageBytes);
@Override public void setValues(PreparedStatement preparedStatement, Message<?> requestMessage, Object groupId, String region, boolean priorityEnabled) throws SQLException { super.setValues(preparedStatement, requestMessage, groupId, region, priorityEnabled); byte[] messageBytes = this.serializer.convert(requestMessage); this.lobHandler.getLobCreator().setBlobAsBytes(preparedStatement, 6, messageBytes); }
@Override public byte[] convert(Object source) { if (source instanceof String) { return ((String) source).getBytes(); } else { return this.serializingConverter.convert(source); } }
@Override public byte[] convert(Object source) { if (source instanceof String) { return ((String) source).getBytes(); } else { return this.serializingConverter.convert(source); } }
@Override @SuppressWarnings("unchecked") public <T> Message<T> addMessage(final Message<T> message) { UUID id = message.getHeaders().getId(); Assert.notNull(id, "Cannot store messages without an ID header"); final String messageId = getKey(id); final byte[] messageBytes = this.serializer.convert(message); if (logger.isDebugEnabled()) { logger.debug("Inserting message with id key=" + messageId); } try { this.jdbcTemplate.update(getQuery(Query.CREATE_MESSAGE), ps -> { ps.setString(1, messageId); ps.setString(2, this.region); ps.setTimestamp(3, new Timestamp(System.currentTimeMillis())); this.lobHandler.getLobCreator().setBlobAsBytes(ps, 4, messageBytes); }); } catch (DuplicateKeyException e) { if (logger.isDebugEnabled()) { logger.debug("The Message with id [" + id + "] already exists.\n" + "Ignoring INSERT and SELECT existing..."); } return (Message<T>) getMessage(id); } return message; }
byte[] messageBytes = this.serializer.convert(requestMessage); this.lobHandler.getLobCreator().setBlobAsBytes(preparedStatement, 6, messageBytes);
.withPartitionKey("partition1") .withSequenceNumber("1") .withData(ByteBuffer.wrap(serializingConverter.convert("foo"))), new Record() .withPartitionKey("partition1") .withSequenceNumber("2") .withData(ByteBuffer.wrap(serializingConverter.convert("bar"))))); .withPartitionKey("partition1") .withSequenceNumber("2") .withData(ByteBuffer.wrap(serializingConverter.convert("bar")))));