fields.add(field[i]);
// encode them
ByteBuffer buffer = BufferUtil.allocate(4096);
int pos = BufferUtil.flipToFill(buffer);
encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields));
BufferUtil.flipToFlush(buffer,pos);
// something was encoded!
assertThat(buffer.remaining(),Matchers.greaterThan(0));
// All are in the header table
Assert.assertEquals(4,encoder.getContext().size());
// encode exact same fields again!
BufferUtil.clearToFill(buffer);
encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields));
BufferUtil.flipToFlush(buffer,0);
// All are in the header table
Assert.assertEquals(4,encoder.getContext().size());
// Add 4 more fields
for (int i=4;i<=7;i++)
fields.add(field[i]);
// encode
BufferUtil.clearToFill(buffer);
encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields));
BufferUtil.flipToFlush(buffer,0);
// something was encoded!
assertThat(buffer.remaining(),Matchers.greaterThan(0));
// max header table size reached
Assert.assertEquals(5,encoder.getContext().size());
// remove some fields
for (int i=0;i<=7;i+=2)
fields.remove(field[i].getName());
// encode
BufferUtil.clearToFill(buffer);
encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields));
BufferUtil.flipToFlush(buffer,0);
// something was encoded!
assertThat(buffer.remaining(),Matchers.greaterThan(0));
// max header table size reached
Assert.assertEquals(5,encoder.getContext().size());
// remove another fields
fields.remove(field[1].getName());
// encode
BufferUtil.clearToFill(buffer);
encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields));
BufferUtil.flipToFlush(buffer,0);
// something was encoded!
assertThat(buffer.remaining(),Matchers.greaterThan(0));
// max header table size reached
Assert.assertEquals(5,encoder.getContext().size());
// re add the field
fields.add(field[1]);
// encode
BufferUtil.clearToFill(buffer);
encoder.encode(buffer,new MetaData(HttpVersion.HTTP_2,fields));
BufferUtil.flipToFlush(buffer,0);
// something was encoded!
assertThat(buffer.remaining(),Matchers.greaterThan(0));