Disable onCommit after first commit

At times OnCommittedResponseWrapper#onResponseCommitted() can be invoked
multiple times. For example, when flush is performed multiple times. This
means that the session can be written multiple times which is inefficient.
Instead, we should only save on the first update.

Fixes gh-57
This commit is contained in:
Rob Winch
2014-10-13 15:32:33 -05:00
parent 2a558885ad
commit 1ad47fc7b1
2 changed files with 18 additions and 1 deletions

View File

@@ -28,7 +28,7 @@ public class OnCommittedResponseWrapperTests {
@Mock
ServletOutputStream out;
HttpServletResponse response;
OnCommittedResponseWrapper response;
boolean committed;
@@ -1069,4 +1069,20 @@ public class OnCommittedResponseWrapperTests {
assertThat(committed).isTrue();
}
@Test
public void bufferSizeCommitsOnce() throws Exception {
String expected = "1234567890";
when(response.getBufferSize()).thenReturn(expected.length());
response.getWriter().write(expected);
assertThat(committed).isTrue();
committed = false;
response.getWriter().write(expected);
assertThat(committed).isFalse();
}
}