< prev index next >

test/jdk/java/foreign/channels/TestSocketChannels.java

Print this page
*** 38,14 ***
  import java.util.Arrays;
  import java.util.List;
  import java.util.concurrent.atomic.AtomicReference;
  import java.util.function.Supplier;
  import java.util.stream.Stream;
! import jdk.incubator.foreign.MemoryAccess;
  import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.foreign.ResourceScope;
  import org.testng.annotations.*;
  import static org.testng.Assert.*;
  
  /**
   * Tests consisting of buffer views with synchronous NIO network channels.
   */
--- 38,16 ---
  import java.util.Arrays;
  import java.util.List;
  import java.util.concurrent.atomic.AtomicReference;
  import java.util.function.Supplier;
  import java.util.stream.Stream;
! 
  import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.foreign.ResourceScope;
  import org.testng.annotations.*;
+ 
+ import static jdk.incubator.foreign.ValueLayout.JAVA_BYTE;
  import static org.testng.Assert.*;
  
  /**
   * Tests consisting of buffer views with synchronous NIO network channels.
   */

*** 99,11 ***
               var sc2 = connectChannels(ssc, sc1);
               var scp = closeableScopeOrNull(scope = scopeSupplier.get())) {
              MemorySegment segment1 = MemorySegment.allocateNative(10, 1, scope);
              MemorySegment segment2 = MemorySegment.allocateNative(10, 1, scope);
              for (int i = 0; i < 10; i++) {
!                 MemoryAccess.setByteAtOffset(segment1, i, (byte) i);
              }
              ByteBuffer bb1 = segment1.asByteBuffer();
              ByteBuffer bb2 = segment2.asByteBuffer();
              assertEquals(sc1.write(bb1), 10);
              assertEquals(sc2.read(bb2), 10);
--- 101,11 ---
               var sc2 = connectChannels(ssc, sc1);
               var scp = closeableScopeOrNull(scope = scopeSupplier.get())) {
              MemorySegment segment1 = MemorySegment.allocateNative(10, 1, scope);
              MemorySegment segment2 = MemorySegment.allocateNative(10, 1, scope);
              for (int i = 0; i < 10; i++) {
!                 segment1.set(JAVA_BYTE, i, (byte) i);
              }
              ByteBuffer bb1 = segment1.asByteBuffer();
              ByteBuffer bb2 = segment2.asByteBuffer();
              assertEquals(sc1.write(bb1), 10);
              assertEquals(sc2.read(bb2), 10);

*** 117,11 ***
               var ssc = ServerSocketChannel.open();
               var sc2 = connectChannels(ssc, sc1)) {
              var segment1 = MemorySegment.ofArray(new byte[10]);
              var segment2 = MemorySegment.ofArray(new byte[10]);
              for (int i = 0; i < 10; i++) {
!                 MemoryAccess.setByteAtOffset(segment1, i, (byte) i);
              }
              ByteBuffer bb1 = segment1.asByteBuffer();
              ByteBuffer bb2 = segment2.asByteBuffer();
              assertEquals(sc1.write(bb1), 10);
              assertEquals(sc2.read(bb2), 10);
--- 119,11 ---
               var ssc = ServerSocketChannel.open();
               var sc2 = connectChannels(ssc, sc1)) {
              var segment1 = MemorySegment.ofArray(new byte[10]);
              var segment2 = MemorySegment.ofArray(new byte[10]);
              for (int i = 0; i < 10; i++) {
!                 segment1.set(JAVA_BYTE, i, (byte) i);
              }
              ByteBuffer bb1 = segment1.asByteBuffer();
              ByteBuffer bb2 = segment2.asByteBuffer();
              assertEquals(sc1.write(bb1), 10);
              assertEquals(sc2.read(bb2), 10);
< prev index next >