File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
main/java/org/threadly/litesockets/buffers
test/java/org/threadly/litesockets/buffers Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -135,7 +135,7 @@ public int get(final byte[] destBytes) {
135135 public ByteBuffer pullBuffer (final int size ) {
136136 if (lock .isLocked ()) {
137137 if (lock .isHeldByCurrentThread ()) {
138- final ByteBuffer bb = super .pullBuffer (size );
138+ final ByteBuffer bb = super .pullBuffer (size ). duplicate () ;
139139 consumedSinceBegin +=size ;
140140 return bb ;
141141 } else {
Original file line number Diff line number Diff line change 44import static org .junit .Assert .assertTrue ;
55
66import java .nio .ByteBuffer ;
7+ import java .util .ArrayList ;
78import java .util .concurrent .atomic .AtomicBoolean ;
89
910import org .junit .After ;
@@ -62,6 +63,27 @@ public boolean get() {
6263 }
6364 }
6465
66+
67+ @ Test
68+ public void rollBackWithBuffersActive () {
69+ int bufferSize = 1000000 ;
70+ TransactionalByteBuffers tbb = new TransactionalByteBuffers ();
71+ tbb .add (ByteBuffer .allocate (bufferSize ));
72+ ArrayList <ByteBuffer > lbb =new ArrayList <>();
73+ tbb .begin ();
74+ while (tbb .hasRemaining ()) {
75+ lbb .add (tbb .pullBuffer (Math .min (100 , tbb .remaining ())));
76+ }
77+ tbb .rollback ();
78+ int countSize = 0 ;
79+ for (ByteBuffer bb : lbb ) {
80+ countSize +=bb .remaining ();
81+ }
82+ assertEquals (bufferSize , countSize );
83+ assertEquals (bufferSize , tbb .remaining ());
84+
85+ }
86+
6587 @ Test
6688 public void getArrayTest () {
6789 String s = "TEST1234567890" ;
You can’t perform that action at this time.
0 commit comments