Skip to content

Commit 5fb2d35

Browse files
committed
writeTo_ConcurrentWrites_HandlesCorrectly no longer needed since even Apache 4.x doesnot suports this
1 parent 7f9e77f commit 5fb2d35

File tree

2 files changed

+5
-103
lines changed

2 files changed

+5
-103
lines changed

http-clients/apache-client/src/test/java/software/amazon/awssdk/http/apache/internal/RepeatableInputStreamRequestEntityTest.java

Lines changed: 4 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@
3636
import java.io.InputStream;
3737
import java.io.InterruptedIOException;
3838
import java.net.URI;
39-
import java.util.ArrayList;
40-
import java.util.Collections;
41-
import java.util.List;
4239
import java.util.Random;
43-
import java.util.concurrent.CountDownLatch;
44-
import java.util.concurrent.TimeUnit;
4540
import java.util.concurrent.atomic.AtomicInteger;
4641
import org.junit.jupiter.api.BeforeEach;
4742
import org.junit.jupiter.api.DisplayName;
@@ -344,7 +339,9 @@ public int read() throws IOException {
344339
return -1;
345340
}
346341
hasBeenRead = true;
347-
return data[position++] & 0xFF;
342+
int i = data[position] & 0xFF;
343+
position++;
344+
return i;
348345
}
349346

350347
@Override
@@ -671,51 +668,6 @@ void constructor_WithoutContentType_HandlesGracefully() {
671668
assertEquals(100L, entity.getContentLength());
672669
}
673670

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-
719671
@Test
720672
@DisplayName("Entity should handle interrupted IO operations")
721673
void writeTo_InterruptedStream_ThrowsIOException() throws IOException {
@@ -882,7 +834,7 @@ public boolean markSupported() {
882834
}
883835

884836
@Override
885-
public synchronized void reset() {
837+
public synchronized void reset() {
886838
resetCalls.incrementAndGet();
887839
throw new RuntimeException("Reset not supported");
888840
}

http-clients/apache5-client/src/test/java/software/amazon/awssdk/http/apache5/internal/RepeatableInputStreamRequestEntityTest.java

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,7 @@
3636
import java.io.InputStream;
3737
import java.io.InterruptedIOException;
3838
import java.net.URI;
39-
import java.util.ArrayList;
40-
import java.util.Collections;
41-
import java.util.List;
4239
import java.util.Random;
43-
import java.util.concurrent.CountDownLatch;
44-
import java.util.concurrent.TimeUnit;
4540
import java.util.concurrent.atomic.AtomicInteger;
4641
import org.junit.jupiter.api.BeforeEach;
4742
import org.junit.jupiter.api.DisplayName;
@@ -671,51 +666,6 @@ void constructor_WithoutContentType_HandlesGracefully() {
671666
assertEquals(100L, entity.getContentLength());
672667
}
673668

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-
719669
@Test
720670
@DisplayName("Entity should handle interrupted IO operations")
721671
void writeTo_InterruptedStream_ThrowsIOException() throws IOException {
@@ -880,7 +830,7 @@ public boolean markSupported() {
880830
}
881831

882832
@Override
883-
public synchronized void reset() {
833+
public synchronized void reset() {
884834
resetCalls.incrementAndGet();
885835
throw new RuntimeException("Reset not supported");
886836
}

0 commit comments

Comments
 (0)