Package com.taobao.metamorphosis

Examples of com.taobao.metamorphosis.Message


                throw new RuntimeException();
            }

        });
        listener.afterPropertiesSet();
        Message message = new Message("test", messageBodyConverter.toByteArray("hello world"));
        listener.recieveMessages(message);

        assertNull(listener.recvMsg);
        assertTrue(MessageAccessor.isRollbackOnly(message));
    }
View Full Code Here


        buf.position(MessageUtils.HEADER_LEN);
        buf.put("hello".getBytes());
        this.it = new MessageIterator("test", buf.array());
        assertTrue(this.it.hasNext());
        final Message msg = this.it.next();
        assertNotNull(msg);
        assertEquals(9999L, msg.getId());
        assertEquals("test", msg.getTopic());
        assertFalse(msg.hasAttribute());
        assertEquals(0, MessageAccessor.getFlag(msg));
        assertEquals("hello", new String(msg.getData()));

    }
View Full Code Here

    @Test
    public void testOnReceiveMessagesWithoutConverter() throws Exception {
        MyMessageListener listener = new MyMessageListener();
        JavaSerializationMessageBodyConverter messageBodyConverter = new JavaSerializationMessageBodyConverter();
        listener.afterPropertiesSet();
        Message message = new Message("test", messageBodyConverter.toByteArray("hello world"));
        listener.recieveMessages(message);

        assertNotNull(listener.recvMsg);
        assertNull(listener.recvMsg.getBody());
        assertSame(message, listener.recvMsg.getRawMessage());
View Full Code Here

    config.setZkConfig(zkConfig);
    MetaMessageSessionFactory factory = new MetaMessageSessionFactory(config);
    MessageProducer producer = factory.createProducer(false);
    String topic = "test";
    producer.publish(topic);
    Message message = new Message(topic, new byte[128]);
    producer.sendMessage(message);
   
  }
View Full Code Here

        buf.position(MessageUtils.HEADER_LEN);
        buf.put(dataBuf);

        this.it = new MessageIterator("test", buf.array());
        assertTrue(this.it.hasNext());
        final Message msg = this.it.next();
        assertNotNull(msg);
        assertEquals(9999L, msg.getId());
        assertEquals("test", msg.getTopic());
        assertTrue(msg.hasAttribute());
        assertEquals("attribute", msg.getAttribute());
        assertEquals(1, MessageAccessor.getFlag(msg));
        assertEquals("hello", new String(msg.getData()));
        assertFalse(this.it.hasNext());
        assertEquals(38, this.it.getOffset());

    }
View Full Code Here

    @Test
    public void testSendOrderedMessage() throws Exception {
        final String topic = "topic1";
        final byte[] data = "hello".getBytes();
        final Message message = new Message(topic, data);
        final String url = "meta://localhost:0";
        final Partition partition = new Partition("0-0");
        EasyMock.expect(this.producerZooKeeper.selectPartition(topic, message, this.partitionSelector))
        .andReturn(partition).times(2);
        EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(url);
        EasyMock.expect(this.localMessageStorageManager.getMessageCount(topic, partition)).andReturn(0);
        OpaqueGenerator.resetOpaque();
        final int flag = MessageFlagUtils.getFlag(null);
        EasyMock.expect(
            this.remotingClient.invokeToGroup(url, new PutCommand(topic, partition.getPartition(), data, flag, CheckSum.crc32(data),
                null, Integer.MIN_VALUE), 3000, TimeUnit.MILLISECONDS)).andReturn(
                    new BooleanCommand(200, "1111 1 1024", Integer.MIN_VALUE));
        this.mocksControl.replay();
        assertEquals(0, message.getId());
        final SendResult sendResult = this.producer.sendMessage(message);

        this.mocksControl.verify();
        assertTrue(sendResult.isSuccess());
        assertEquals(1024, sendResult.getOffset());
        assertEquals(1, sendResult.getPartition().getPartition());
        assertEquals(0, sendResult.getPartition().getBrokerId());
        assertEquals(1111, message.getId());
    }
View Full Code Here

        }
        catch (final InvalidMessageException e) {
            assertEquals("Null message", e.getMessage());
        }
        try {
            this.producer.sendMessage(new Message(null, "hello".getBytes()));
            fail();
        }
        catch (final InvalidMessageException e) {
            assertEquals("Blank topic", e.getMessage());
        }
        try {
            this.producer.sendMessage(new Message("topic", null));
            fail();
        }
        catch (final InvalidMessageException e) {
            assertEquals("Null data", e.getMessage());
        }
View Full Code Here

    public void testBuildMessageWithBodyObject() throws Exception {
        MessageBuilder mb = MessageBuilder.withTopic("test");
        mb.withAttribute("a attribute").withBody(new MyTest());

        JavaSerializationMessageBodyConverter converter = new JavaSerializationMessageBodyConverter();
        Message msg = mb.build(converter);
        assertNotNull(msg);
        assertEquals("test", msg.getTopic());
        assertEquals("a attribute", msg.getAttribute());
        assertTrue(msg.hasAttribute());
        byte[] data = msg.getData();
        Object obj = converter.fromByteArray(data);
        assertTrue(obj instanceof MyTest);
        assertEquals(1000L, ((MyTest) obj).getValue());
    }
View Full Code Here

    public void sendMessage(final int count, final String strdata, final String topic) throws Exception {
        this.messages = new ArrayList<Message>();
        final CountDownLatch latch = new CountDownLatch(count);
        for (int i = 0; i < count; i++) {
            final byte[] data = (strdata + i).getBytes();
            final Message msg = new Message(topic, data);
            this.producer.sendMessage(msg, new SendMessageCallback() {
                public void onMessageSent(final SendResult result) {
                    latch.countDown();
                    if (!result.isSuccess()) {
                        throw new RuntimeException("Send message failed:" + result.getErrorMessage());
View Full Code Here

    @Test
    public void testSendMessage_PartitionNumWrong() throws Exception {
        // ��⵽����������,������Ϣ�洢������

        final Message message = this.createDefaultMessage();
        // EasyMock.expect(this.producer.getLocalMessageCount(message.getTopic(),
        // this.partition)).andReturn(2);
        EasyMock.expect(this.producer.selectPartition(message)).andThrow(
            new AvailablePartitionNumException("xx[0-0]xx"));
        EasyMock.expect(this.producer.saveMessageToLocal(message, this.partition, 10000, TimeUnit.MILLISECONDS))
View Full Code Here

TOP

Related Classes of com.taobao.metamorphosis.Message

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.