< prev index next >

test/jdk/java/foreign/channels/AbstractChannelsTest.java

Print this page
*** 20,22 ***
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
  import java.io.IOException;
- import java.lang.ref.Cleaner;
  import java.nio.ByteBuffer;
  import java.util.Arrays;
  import java.util.Random;
  import java.util.concurrent.ExecutionException;
  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 jdk.test.lib.RandomFactory;
  import org.testng.annotations.*;
  import static org.testng.Assert.*;
  
  /**
   * Not a test, but infra for channel tests.
   */
--- 20,23 ---
   * or visit www.oracle.com if you need additional information or have any
   * questions.
   */
  
  import java.io.IOException;
  import java.nio.ByteBuffer;
  import java.util.Arrays;
  import java.util.Random;
  import java.util.concurrent.ExecutionException;
  import java.util.function.Supplier;
  import java.util.stream.Stream;
! 
  import jdk.incubator.foreign.MemorySegment;
  import jdk.incubator.foreign.ResourceScope;
  import jdk.test.lib.RandomFactory;
  import org.testng.annotations.*;
+ 
+ import static jdk.incubator.foreign.ValueLayout.JAVA_BYTE;
  import static org.testng.Assert.*;
  
  /**
   * Not a test, but infra for channel tests.
   */

*** 49,11 ***
      interface ThrowingConsumer<T, X extends Throwable> {
          void accept(T action) throws X;
      }
  
      static ResourceScope closeableScopeOrNull(ResourceScope scope) {
!         if (scope.isImplicit())
              return null;
          return scope;
      }
  
      static long remaining(ByteBuffer[] buffers) {
--- 50,11 ---
      interface ThrowingConsumer<T, X extends Throwable> {
          void accept(T action) throws X;
      }
  
      static ResourceScope closeableScopeOrNull(ResourceScope scope) {
!         if (scope == ResourceScope.globalScope())
              return null;
          return scope;
      }
  
      static long remaining(ByteBuffer[] buffers) {

*** 73,11 ***
      static final Random RANDOM = RandomFactory.getRandom();
  
      static ByteBuffer segmentBufferOfSize(ResourceScope scope, int size) {
          var segment = MemorySegment.allocateNative(size, 1, scope);
          for (int i = 0; i < size; i++) {
!             MemoryAccess.setByteAtOffset(segment, i, ((byte)RANDOM.nextInt()));
          }
          return segment.asByteBuffer();
      }
  
      static ByteBuffer[] segmentBuffersOfSize(int len, ResourceScope scope, int size) {
--- 74,11 ---
      static final Random RANDOM = RandomFactory.getRandom();
  
      static ByteBuffer segmentBufferOfSize(ResourceScope scope, int size) {
          var segment = MemorySegment.allocateNative(size, 1, scope);
          for (int i = 0; i < size; i++) {
!             segment.set(JAVA_BYTE, i, ((byte)RANDOM.nextInt()));
          }
          return segment.asByteBuffer();
      }
  
      static ByteBuffer[] segmentBuffersOfSize(int len, ResourceScope scope, int size) {

*** 127,19 ***
  
      @DataProvider(name = "confinedScopes")
      public static Object[][] confinedScopes() {
          return new Object[][] {
                  { ScopeSupplier.NEW_CONFINED          },
-                 { ScopeSupplier.NEW_CONFINED_EXPLICIT },
          };
      }
  
      @DataProvider(name = "sharedScopes")
      public static Object[][] sharedScopes() {
          return new Object[][] {
                  { ScopeSupplier.NEW_SHARED          },
-                 { ScopeSupplier.NEW_SHARED_EXPLICIT },
          };
      }
  
      @DataProvider(name = "closeableScopes")
      public static Object[][] closeableScopes() {
--- 128,17 ---

*** 149,11 ***
      }
  
      @DataProvider(name = "implicitScopes")
      public static Object[][] implicitScopes() {
          return new Object[][] {
-                 { ScopeSupplier.NEW_IMPLICIT },
                  { ScopeSupplier.GLOBAL       },
          };
      }
  
      @DataProvider(name = "sharedAndImplicitScopes")
--- 148,10 ---

*** 172,30 ***
  
      @DataProvider(name = "sharedScopesAndTimeouts")
      public static Object[][] sharedScopesAndTimeouts() {
          return new Object[][] {
                  { ScopeSupplier.NEW_SHARED          ,  0 },
-                 { ScopeSupplier.NEW_SHARED_EXPLICIT ,  0 },
                  { ScopeSupplier.NEW_SHARED          , 30 },
-                 { ScopeSupplier.NEW_SHARED_EXPLICIT , 30 },
          };
      }
  
      static class ScopeSupplier implements Supplier<ResourceScope> {
  
          static final Supplier<ResourceScope> NEW_CONFINED =
!                 new ScopeSupplier(() -> ResourceScope.newConfinedScope(), "newConfinedScope()");
-         static final Supplier<ResourceScope> NEW_CONFINED_EXPLICIT =
-                 new ScopeSupplier(() -> ResourceScope.newConfinedScope(Cleaner.create()), "newConfinedScope(Cleaner)");
          static final Supplier<ResourceScope> NEW_SHARED =
!                 new ScopeSupplier(() -> ResourceScope.newSharedScope(), "newSharedScope()");
-         static final Supplier<ResourceScope> NEW_SHARED_EXPLICIT =
-                 new ScopeSupplier(() -> ResourceScope.newSharedScope(Cleaner.create()), "newSharedScope(Cleaner)");
          static final Supplier<ResourceScope> NEW_IMPLICIT =
!                 new ScopeSupplier(() -> ResourceScope.newImplicitScope(), "newImplicitScope()");
          static final Supplier<ResourceScope> GLOBAL =
!                 new ScopeSupplier(() -> ResourceScope.globalScope(), "globalScope()");
  
          private final Supplier<ResourceScope> supplier;
          private final String str;
          private ScopeSupplier(Supplier<ResourceScope> supplier, String str) {
              this.supplier = supplier;
--- 170,24 ---
  
      @DataProvider(name = "sharedScopesAndTimeouts")
      public static Object[][] sharedScopesAndTimeouts() {
          return new Object[][] {
                  { ScopeSupplier.NEW_SHARED          ,  0 },
                  { ScopeSupplier.NEW_SHARED          , 30 },
          };
      }
  
      static class ScopeSupplier implements Supplier<ResourceScope> {
  
          static final Supplier<ResourceScope> NEW_CONFINED =
!                 new ScopeSupplier(ResourceScope::newConfinedScope, "newConfinedScope()");
          static final Supplier<ResourceScope> NEW_SHARED =
!                 new ScopeSupplier(ResourceScope::newSharedScope, "newSharedScope()");
          static final Supplier<ResourceScope> NEW_IMPLICIT =
!                 new ScopeSupplier(ResourceScope::newImplicitScope, "newImplicitScope()");
          static final Supplier<ResourceScope> GLOBAL =
!                 new ScopeSupplier(ResourceScope::globalScope, "globalScope()");
  
          private final Supplier<ResourceScope> supplier;
          private final String str;
          private ScopeSupplier(Supplier<ResourceScope> supplier, String str) {
              this.supplier = supplier;
< prev index next >