@Test
public void testSendOrderedMessageServerError() 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");
// �����ظ�3��
EasyMock.expect(this.producerZooKeeper.selectPartition(topic, message, this.partitionSelector)).andReturn(
partition);// .times(3);
EasyMock.expect(this.producerZooKeeper.selectBroker(topic, partition)).andReturn(url);// .times(3);
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(500, "server error", Integer.MIN_VALUE));
// EasyMock.expect(
// this.remotingClient.invokeToGroup(url, new PutCommand(topic,
// partition.getPartition(), data, null, flag,
// Integer.MIN_VALUE + 1), 3000, TimeUnit.MILLISECONDS)).andReturn(
// new BooleanCommand(Integer.MIN_VALUE, 500, "server error"));
// EasyMock.expect(
// this.remotingClient.invokeToGroup(url, new PutCommand(topic,
// partition.getPartition(), data, null, flag,
// Integer.MIN_VALUE + 2), 3000, TimeUnit.MILLISECONDS)).andReturn(
// new BooleanCommand(Integer.MIN_VALUE, 500, "server error"));
this.mocksControl.replay();
assertEquals(0, message.getId());
final SendResult sendResult = this.producer.sendMessage(message);
this.mocksControl.verify();
assertFalse(sendResult.isSuccess());
assertEquals(-1, sendResult.getOffset());