rabbitmq-tests/src/test/java/com/datastax/oss/starlight/rabbitmqtests/javaclient/functional/FrameMax.java
@Test
  public void rejectHeadersExceedingFrameMax() throws IOException, TimeoutException {
    declareDurableDirectExchange("x");
    String queueName = channel.queueDeclare().getQueue();
    channel.queueBind(queueName, "x", "foobar");

    Map<String, Object> headers = new HashMap<String, Object>();
    String headerName = "x-huge-header";

    // create headers with zero-length value to calculate maximum header value size before exceeding
    // frame_max
    headers.put(headerName, LongStringHelper.asLongString(new byte[0]));
    AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder().headers(headers).build();
    Frame minimalHeaderFrame = properties.toFrame(0, 0);
    int maxHeaderValueSize = FRAME_MAX - minimalHeaderFrame.size();

    // create headers with maximum header value size (frame size equals frame_max)
    headers.put(headerName, LongStringHelper.asLongString(new byte[maxHeaderValueSize]));
    properties = new AMQP.BasicProperties.Builder().headers(headers).build();

    basicPublishVolatile(new byte[100], "x", "foobar", properties);
    assertDelivered(queueName, 1);

    // create headers with frame size exceeding frame_max by 1
    headers.put(headerName, LongStringHelper.asLongString(new byte[maxHeaderValueSize + 1]));
    properties = new AMQP.BasicProperties.Builder().headers(headers).build();
    try {
      basicPublishVolatile(new byte[100], "x", "foobar", properties);
      fail("expected rejectHeadersExceedingFrameMax to throw");
    } catch (IllegalArgumentException iae) {
      assertTrue(iae.getMessage().startsWith("Content headers exceeded max frame size"));
      // check that the channel is still operational
      assertDelivered(queueName, 0);
    }

    // cleanup
    deleteExchange("x");
  }
/* client should throw exception if headers exceed negotiated
   * frame size */
client should throw exception if headers exceed negotiated
frame size
client should throw exception if headers exceed negotiated frame size
@Test
  public void rejectHeadersExceedingFrameMax() throws IOException, TimeoutException {
    declareDurableDirectExchange("x");
    String queueName = channel.queueDeclare().getQueue();
    channel.queueBind(queueName, "x", "foobar");
    Map<String, Object> headers = new HashMap<String, Object>();
    String headerName = "x-huge-header";
    headers.put(headerName, LongStringHelper.asLongString(new byte[0]));
    AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder().headers(headers).build();
    Frame minimalHeaderFrame = properties.toFrame(0, 0);
    int maxHeaderValueSize = FRAME_MAX - minimalHeaderFrame.size();
    headers.put(headerName, LongStringHelper.asLongString(new byte[maxHeaderValueSize]));
    properties = new AMQP.BasicProperties.Builder().headers(headers).build();
    basicPublishVolatile(new byte[100], "x", "foobar", properties);
    assertDelivered(queueName, 1);
    headers.put(headerName, LongStringHelper.asLongString(new byte[maxHeaderValueSize + 1]));
    properties = new AMQP.BasicProperties.Builder().headers(headers).build();
    try {
      basicPublishVolatile(new byte[100], "x", "foobar", properties);
      fail("expected rejectHeadersExceedingFrameMax to throw");
    } catch (IllegalArgumentException iae) {
      assertTrue(iae.getMessage().startsWith("Content headers exceeded max frame size"));
      assertDelivered(queueName, 0);
    }
    deleteExchange("x");
  }
@ Test public void rejectHeadersExceedingFrameMax ( ) throws IOException , TimeoutException { declareDurableDirectExchange ( "x" ) ; String queueName = channel . queueDeclare ( ) . getQueue ( ) ; channel . queueBind ( queueName , "x" , "foobar" ) ; Map < String , Object > headers = new HashMap < String , Object > ( ) ; String headerName = "x-huge-header" ; headers . put ( headerName , LongStringHelper . asLongString ( new byte [ 0 ] ) ) ; AMQP . BasicProperties properties = new AMQP . BasicProperties . Builder ( ) . headers ( headers ) . build ( ) ; Frame minimalHeaderFrame = properties . toFrame ( 0 , 0 ) ; int maxHeaderValueSize = FRAME_MAX - minimalHeaderFrame . size ( ) ; headers . put ( headerName , LongStringHelper . asLongString ( new byte [ maxHeaderValueSize ] ) ) ; properties = new AMQP . BasicProperties . Builder ( ) . headers ( headers ) . build ( ) ; basicPublishVolatile ( new byte [ 100 ] , "x" , "foobar" , properties ) ; assertDelivered ( queueName , 1 ) ; headers . put ( headerName , LongStringHelper . asLongString ( new byte [ maxHeaderValueSize + 1 ] ) ) ; properties = new AMQP . BasicProperties . Builder ( ) . headers ( headers ) . build ( ) ; try { basicPublishVolatile ( new byte [ 100 ] , "x" , "foobar" , properties ) ; fail ( "expected rejectHeadersExceedingFrameMax to throw" ) ; } catch ( IllegalArgumentException iae ) { assertTrue ( iae . getMessage ( ) . startsWith ( "Content headers exceeded max frame size" ) ) ; assertDelivered ( queueName , 0 ) ; } deleteExchange ( "x" ) ; }
client should throw exception if headers exceed negotiated
 frame size
client should throw exception if headers exceed negotiated frame size
// create headers with zero-length value to calculate maximum header value size before exceeding // frame_max // create headers with maximum header value size (frame size equals frame_max) // create headers with frame size exceeding frame_max by 1 // check that the channel is still operational // cleanup