|
36 | 36 | import java.io.InputStream; |
37 | 37 | import java.io.InterruptedIOException; |
38 | 38 | import java.net.URI; |
39 | | -import java.util.ArrayList; |
40 | | -import java.util.Collections; |
41 | | -import java.util.List; |
42 | 39 | import java.util.Random; |
43 | | -import java.util.concurrent.CountDownLatch; |
44 | | -import java.util.concurrent.TimeUnit; |
45 | 40 | import java.util.concurrent.atomic.AtomicInteger; |
46 | 41 | import org.junit.jupiter.api.BeforeEach; |
47 | 42 | import org.junit.jupiter.api.DisplayName; |
@@ -344,7 +339,9 @@ public int read() throws IOException { |
344 | 339 | return -1; |
345 | 340 | } |
346 | 341 | hasBeenRead = true; |
347 | | - return data[position++] & 0xFF; |
| 342 | + int i = data[position] & 0xFF; |
| 343 | + position++; |
| 344 | + return i; |
348 | 345 | } |
349 | 346 |
|
350 | 347 | @Override |
@@ -671,51 +668,6 @@ void constructor_WithoutContentType_HandlesGracefully() { |
671 | 668 | assertEquals(100L, entity.getContentLength()); |
672 | 669 | } |
673 | 670 |
|
674 | | - @Test |
675 | | - @DisplayName("Entity should handle concurrent write attempts") |
676 | | - void writeTo_ConcurrentWrites_HandlesCorrectly() throws Exception { |
677 | | - // Given |
678 | | - String content = "Concurrent test content"; |
679 | | - ContentStreamProvider provider = () -> new ByteArrayInputStream(content.getBytes()); |
680 | | - SdkHttpRequest httpRequest = httpRequestBuilder.build(); |
681 | | - HttpExecuteRequest request = HttpExecuteRequest.builder() |
682 | | - .request(httpRequest) |
683 | | - .contentStreamProvider(provider) |
684 | | - .build(); |
685 | | - |
686 | | - entity = new RepeatableInputStreamRequestEntity(request); |
687 | | - |
688 | | - // Simulate concurrent writes |
689 | | - int threadCount = 5; |
690 | | - CountDownLatch latch = new CountDownLatch(threadCount); |
691 | | - List<ByteArrayOutputStream> outputs = Collections.synchronizedList(new ArrayList<>()); |
692 | | - List<Exception> exceptions = Collections.synchronizedList(new ArrayList<>()); |
693 | | - |
694 | | - for (int i = 0; i < threadCount; i++) { |
695 | | - new Thread(() -> { |
696 | | - try { |
697 | | - ByteArrayOutputStream output = new ByteArrayOutputStream(); |
698 | | - entity.writeTo(output); |
699 | | - outputs.add(output); |
700 | | - } catch (Exception e) { |
701 | | - exceptions.add(e); |
702 | | - } finally { |
703 | | - latch.countDown(); |
704 | | - } |
705 | | - }).start(); |
706 | | - } |
707 | | - |
708 | | - latch.await(5, TimeUnit.SECONDS); |
709 | | - |
710 | | - // At least one should succeed, others may fail due to stream state |
711 | | - assertFalse(outputs.isEmpty(), "At least one write should succeed"); |
712 | | - for (ByteArrayOutputStream output : outputs) { |
713 | | - if (output.size() > 0) { |
714 | | - assertEquals(content, output.toString()); |
715 | | - } |
716 | | - } |
717 | | - } |
718 | | - |
719 | 671 | @Test |
720 | 672 | @DisplayName("Entity should handle interrupted IO operations") |
721 | 673 | void writeTo_InterruptedStream_ThrowsIOException() throws IOException { |
@@ -882,7 +834,7 @@ public boolean markSupported() { |
882 | 834 | } |
883 | 835 |
|
884 | 836 | @Override |
885 | | - public synchronized void reset() { |
| 837 | + public synchronized void reset() { |
886 | 838 | resetCalls.incrementAndGet(); |
887 | 839 | throw new RuntimeException("Reset not supported"); |
888 | 840 | } |
|
0 commit comments