Skip to content

Commit

Permalink
GH-2552: Fix Builder Argument Types maxLength etc
Browse files Browse the repository at this point in the history
Resolves #2552

Variables map to Erlang ints which are 8 bytes, so need to be long in Java.
  • Loading branch information
garyrussell authored Oct 31, 2023
1 parent 1b38f94 commit 613c289
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2022 the original author or authors.
* Copyright 2016-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -150,12 +150,26 @@ public QueueBuilder expires(int expires) {
* @param count the number of (ready) messages allowed.
* @return the builder.
* @since 2.2
* @deprecated in favor of {@link #maxLength(long)}.
* @see #overflow(Overflow)
*/
@Deprecated
public QueueBuilder maxLength(int count) {
return withArgument("x-max-length", count);
}

/**
* Set the number of (ready) messages allowed in the queue before it starts to drop
* them.
* @param count the number of (ready) messages allowed.
* @return the builder.
* @since 3.1
* @see #overflow(Overflow)
*/
public QueueBuilder maxLength(long count) {
return withArgument("x-max-length", count);
}

/**
* Set the total aggregate body size allowed in the queue before it starts to drop
* them.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* Based on <a href="https://www.rabbitmq.com/streams.html">Streams documentation</a>
*
* @author Sergei Kurenchuk
* @author Gary Russell
* @since 3.1
*/
public class SuperStreamBuilder {
Expand Down Expand Up @@ -73,7 +74,7 @@ public SuperStreamBuilder maxAge(String maxAge) {
* @param bytes the max total size in bytes
* @return the builder
*/
public SuperStreamBuilder maxLength(int bytes) {
public SuperStreamBuilder maxLength(long bytes) {
return withArgument("max-length-bytes", bytes);
}

Expand All @@ -82,7 +83,7 @@ public SuperStreamBuilder maxLength(int bytes) {
* @param bytes the max segments size in bytes
* @return the builder
*/
public SuperStreamBuilder maxSegmentSize(int bytes) {
public SuperStreamBuilder maxSegmentSize(long bytes) {
return withArgument("x-stream-max-segment-size-bytes", bytes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ void builderMustSetupArguments() {
var finalPartitionsNumber = 4;
var finalName = "test-name";
var maxAge = "1D";
var maxLength = 10_000_000;
var maxSegmentsSize = 100_000;
var maxLength = 10_000_000L;
var maxSegmentsSize = 100_000L;
var initialClusterSize = 5;

var testArgName = "test-key";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014-2022 the original author or authors.
* Copyright 2014-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -265,7 +265,7 @@ public Queue allArgs1() {
return QueueBuilder.nonDurable("all.args.1")
.ttl(1000)
.expires(200_000)
.maxLength(42)
.maxLength(42L)
.maxLengthBytes(10_000)
.overflow(Overflow.rejectPublish)
.deadLetterExchange("reply.dlx")
Expand All @@ -282,7 +282,7 @@ public Queue allArgs2() {
return QueueBuilder.nonDurable("all.args.2")
.ttl(1000)
.expires(200_000)
.maxLength(42)
.maxLength(42L)
.maxLengthBytes(10_000)
.overflow(Overflow.dropHead)
.deadLetterExchange("reply.dlx")
Expand All @@ -298,7 +298,7 @@ public Queue allArgs3() {
return QueueBuilder.nonDurable("all.args.3")
.ttl(1000)
.expires(200_000)
.maxLength(42)
.maxLength(42L)
.maxLengthBytes(10_000)
.overflow(Overflow.rejectPublish)
.deadLetterExchange("reply.dlx")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -833,7 +833,7 @@ public void testWithFuture() throws Exception {
RabbitAdmin admin = new RabbitAdmin(this.connectionFactory);
Queue queue = QueueBuilder.nonDurable()
.autoDelete()
.maxLength(1)
.maxLength(1L)
.overflow(Overflow.rejectPublish)
.build();
admin.declareQueue(queue);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2018-2019 the original author or authors.
* Copyright 2018-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -103,7 +103,7 @@ void testCorrelatedWithNack() {
RabbitTemplate template = new RabbitTemplate(ccf);
RabbitAdmin admin = new RabbitAdmin(ccf);
Queue queue = QueueBuilder.durable(QUEUE + ".nack")
.maxLength(1)
.maxLength(1L)
.overflow(Overflow.rejectPublish)
.build();
admin.declareQueue(queue);
Expand Down

0 comments on commit 613c289

Please sign in to comment.