From 6b43f1566f481ead2fde5bf8020966979bfb607c Mon Sep 17 00:00:00 2001 From: christosts Date: Thu, 17 Dec 2020 14:33:56 +0000 Subject: [PATCH] Reduce length of test data in UdpDataSourceContractTest PiperOrigin-RevId: 348011243 --- .../upstream/UdpDataSourceContractTest.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/library/core/src/test/java/com/google/android/exoplayer2/upstream/UdpDataSourceContractTest.java b/library/core/src/test/java/com/google/android/exoplayer2/upstream/UdpDataSourceContractTest.java index 124f4d0140..0dd688fd36 100644 --- a/library/core/src/test/java/com/google/android/exoplayer2/upstream/UdpDataSourceContractTest.java +++ b/library/core/src/test/java/com/google/android/exoplayer2/upstream/UdpDataSourceContractTest.java @@ -43,11 +43,7 @@ public class UdpDataSourceContractTest extends DataSourceContractTest { @Before public void setUp() { udpDataSource = new UdpDataSource(); - // UDP is unreliable: it may lose, duplicate or re-order packets. We want to transmit more than - // one UDP packets to thoroughly test the UDP data source. We assume that UDP delivery within - // the same host is reliable. - int dataLength = (10 * 1024) + 512; // 10.5 KiB, not a round number by intention - data = TestUtil.buildTestData(dataLength); + data = TestUtil.buildTestData(/* length= */ 256); PacketTrasmitterTransferListener transferListener = new PacketTrasmitterTransferListener(data); udpDataSource.addTransferListener(transferListener); } @@ -116,9 +112,11 @@ public class UdpDataSourceContractTest extends DataSourceContractTest { String host = dataSpec.uri.getHost(); int port = dataSpec.uri.getPort(); try (DatagramSocket socket = new DatagramSocket()) { - // Split data in packets of up to 1024 bytes. - for (int offset = 0; offset < data.length; offset += 1024) { - int packetLength = min(1024, data.length - offset); + // Split data in packets of up to 64 bytes: UDP is unreliable, it may lose, duplicate or + // re-order packets. However, we want to transmit more than one UDP packets to thoroughly + // test the UDP data source. We assume that UDP delivery within the same host is reliable. + for (int offset = 0; offset < data.length; offset += 64) { + int packetLength = min(64, data.length - offset); DatagramPacket packet = new DatagramPacket(data, offset, packetLength, InetAddress.getByName(host), port); socket.send(packet);