|
57 | 57 | import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer; |
58 | 58 | import org.springframework.amqp.support.AmqpHeaders; |
59 | 59 | import org.springframework.amqp.support.postprocessor.AbstractCompressingPostProcessor; |
| 60 | +import org.springframework.amqp.support.postprocessor.DeflaterPostProcessor; |
60 | 61 | import org.springframework.amqp.support.postprocessor.DelegatingDecompressingPostProcessor; |
61 | 62 | import org.springframework.amqp.support.postprocessor.GUnzipPostProcessor; |
62 | 63 | import org.springframework.amqp.support.postprocessor.GZipPostProcessor; |
| 64 | +import org.springframework.amqp.support.postprocessor.InflaterPostProcessor; |
63 | 65 | import org.springframework.amqp.support.postprocessor.UnzipPostProcessor; |
64 | 66 | import org.springframework.amqp.support.postprocessor.ZipPostProcessor; |
65 | 67 | import org.springframework.amqp.utils.test.TestUtils; |
|
72 | 74 | * @author Gary Russell |
73 | 75 | * @author Artem Bilan |
74 | 76 | * @author Mohammad Hewedy |
| 77 | + * @author David Diehl |
75 | 78 | * |
76 | 79 | * @since 1.4.1 |
77 | 80 | * |
@@ -517,6 +520,68 @@ public void testSimpleBatchZippedWithEncoding() throws Exception { |
517 | 520 | assertThat(new String(message.getBody())).isEqualTo("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar"); |
518 | 521 | } |
519 | 522 |
|
| 523 | + @Test |
| 524 | + public void testSimpleBatchDeflater() throws Exception { |
| 525 | + BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000); |
| 526 | + BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); |
| 527 | + template.setConnectionFactory(this.connectionFactory); |
| 528 | + DeflaterPostProcessor deflaterPostProcessor = new DeflaterPostProcessor(); |
| 529 | + assertThat(getStreamLevel(deflaterPostProcessor)).isEqualTo(Deflater.BEST_SPEED); |
| 530 | + template.setBeforePublishPostProcessors(deflaterPostProcessor); |
| 531 | + MessageProperties props = new MessageProperties(); |
| 532 | + Message message = new Message("foo".getBytes(), props); |
| 533 | + template.send("", ROUTE, message); |
| 534 | + message = new Message("bar".getBytes(), props); |
| 535 | + template.send("", ROUTE, message); |
| 536 | + message = receive(template); |
| 537 | + assertThat(message.getMessageProperties().getContentEncoding()).isEqualTo("deflate"); |
| 538 | + InflaterPostProcessor inflater = new InflaterPostProcessor(); |
| 539 | + message = inflater.postProcessMessage(message); |
| 540 | + assertThat(new String(message.getBody())).isEqualTo("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar"); |
| 541 | + } |
| 542 | + |
| 543 | + @Test |
| 544 | + public void testSimpleBatchDeflaterBestCompression() throws Exception { |
| 545 | + BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000); |
| 546 | + BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); |
| 547 | + template.setConnectionFactory(this.connectionFactory); |
| 548 | + DeflaterPostProcessor deflaterPostProcessor = new DeflaterPostProcessor(); |
| 549 | + deflaterPostProcessor.setLevel(Deflater.BEST_COMPRESSION); |
| 550 | + assertThat(getStreamLevel(deflaterPostProcessor)).isEqualTo(Deflater.BEST_COMPRESSION); |
| 551 | + template.setBeforePublishPostProcessors(deflaterPostProcessor); |
| 552 | + MessageProperties props = new MessageProperties(); |
| 553 | + Message message = new Message("foo".getBytes(), props); |
| 554 | + template.send("", ROUTE, message); |
| 555 | + message = new Message("bar".getBytes(), props); |
| 556 | + template.send("", ROUTE, message); |
| 557 | + message = receive(template); |
| 558 | + assertThat(message.getMessageProperties().getContentEncoding()).isEqualTo("deflate"); |
| 559 | + InflaterPostProcessor inflater = new InflaterPostProcessor(); |
| 560 | + message = inflater.postProcessMessage(message); |
| 561 | + assertThat(new String(message.getBody())).isEqualTo("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar"); |
| 562 | + } |
| 563 | + |
| 564 | + @Test |
| 565 | + public void testSimpleBatchDeflaterWithEncoding() throws Exception { |
| 566 | + BatchingStrategy batchingStrategy = new SimpleBatchingStrategy(2, Integer.MAX_VALUE, 30000); |
| 567 | + BatchingRabbitTemplate template = new BatchingRabbitTemplate(batchingStrategy, this.scheduler); |
| 568 | + template.setConnectionFactory(this.connectionFactory); |
| 569 | + DeflaterPostProcessor deflaterPostProcessor = new DeflaterPostProcessor(); |
| 570 | + assertThat(getStreamLevel(deflaterPostProcessor)).isEqualTo(Deflater.BEST_SPEED); |
| 571 | + template.setBeforePublishPostProcessors(deflaterPostProcessor); |
| 572 | + MessageProperties props = new MessageProperties(); |
| 573 | + props.setContentEncoding("foo"); |
| 574 | + Message message = new Message("foo".getBytes(), props); |
| 575 | + template.send("", ROUTE, message); |
| 576 | + message = new Message("bar".getBytes(), props); |
| 577 | + template.send("", ROUTE, message); |
| 578 | + message = receive(template); |
| 579 | + assertThat(message.getMessageProperties().getContentEncoding()).isEqualTo("deflate:foo"); |
| 580 | + InflaterPostProcessor inflater = new InflaterPostProcessor(); |
| 581 | + message = inflater.postProcessMessage(message); |
| 582 | + assertThat(new String(message.getBody())).isEqualTo("\u0000\u0000\u0000\u0003foo\u0000\u0000\u0000\u0003bar"); |
| 583 | + } |
| 584 | + |
520 | 585 | private Message receive(BatchingRabbitTemplate template) throws InterruptedException { |
521 | 586 | Message message = template.receive(ROUTE); |
522 | 587 | int n = 0; |
|
0 commit comments