Search in sources :

Example 6 with Pipe

use of java.nio.channels.Pipe in project j2objc by google.

the class ChannelsTest method createNonBlockingChannel.

private Pipe.SourceChannel createNonBlockingChannel(byte[] content) throws IOException {
    Pipe pipe = Pipe.open();
    WritableByteChannel sinkChannel = pipe.sink();
    sinkChannel.write(ByteBuffer.wrap(content));
    Pipe.SourceChannel sourceChannel = pipe.source();
    sourceChannel.configureBlocking(false);
    return sourceChannel;
}
Also used : WritableByteChannel(java.nio.channels.WritableByteChannel) Pipe(java.nio.channels.Pipe)

Example 7 with Pipe

use of java.nio.channels.Pipe in project jdk8u_jdk by JetBrains.

the class Basic method main.

public static void main(String[] args) throws Exception {
    Pipe p = Pipe.open();
    p.source().close();
    p.sink().close();
}
Also used : Pipe(java.nio.channels.Pipe)

Example 8 with Pipe

use of java.nio.channels.Pipe in project beam by apache.

the class PackageUtilTest method testPackageUploadWithDirectorySucceeds.

@Test
public void testPackageUploadWithDirectorySucceeds() throws Exception {
    Pipe pipe = Pipe.open();
    File tmpDirectory = tmpFolder.newFolder("folder");
    tmpFolder.newFolder("folder", "empty_directory");
    tmpFolder.newFolder("folder", "directory");
    makeFileWithContents("folder/file.txt", "This is a test!");
    makeFileWithContents("folder/directory/file.txt", "This is also a test!");
    when(mockGcsUtil.getObjects(anyListOf(GcsPath.class))).thenReturn(ImmutableList.of(StorageObjectOrIOException.create(new FileNotFoundException("some/path"))));
    when(mockGcsUtil.create(any(GcsPath.class), anyString())).thenReturn(pipe.sink());
    PackageUtil.stageClasspathElements(ImmutableList.of(tmpDirectory.getAbsolutePath()), STAGING_PATH, createOptions);
    verify(mockGcsUtil).getObjects(anyListOf(GcsPath.class));
    verify(mockGcsUtil).create(any(GcsPath.class), anyString());
    verifyNoMoreInteractions(mockGcsUtil);
    ZipInputStream inputStream = new ZipInputStream(Channels.newInputStream(pipe.source()));
    List<String> zipEntryNames = new ArrayList<>();
    for (ZipEntry entry = inputStream.getNextEntry(); entry != null; entry = inputStream.getNextEntry()) {
        zipEntryNames.add(entry.getName());
    }
    assertThat(zipEntryNames, containsInAnyOrder("directory/file.txt", "empty_directory/", "file.txt"));
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) ZipEntry(java.util.zip.ZipEntry) GcsPath(org.apache.beam.sdk.util.gcsfs.GcsPath) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) Pipe(java.nio.channels.Pipe) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) Test(org.junit.Test)

Example 9 with Pipe

use of java.nio.channels.Pipe in project beam by apache.

the class PackageUtilTest method testPackageUploadWithEmptyDirectorySucceeds.

@Test
public void testPackageUploadWithEmptyDirectorySucceeds() throws Exception {
    Pipe pipe = Pipe.open();
    File tmpDirectory = tmpFolder.newFolder("folder");
    when(mockGcsUtil.getObjects(anyListOf(GcsPath.class))).thenReturn(ImmutableList.of(StorageObjectOrIOException.create(new FileNotFoundException("some/path"))));
    when(mockGcsUtil.create(any(GcsPath.class), anyString())).thenReturn(pipe.sink());
    List<DataflowPackage> targets = PackageUtil.stageClasspathElements(ImmutableList.of(tmpDirectory.getAbsolutePath()), STAGING_PATH, createOptions);
    DataflowPackage target = Iterables.getOnlyElement(targets);
    verify(mockGcsUtil).getObjects(anyListOf(GcsPath.class));
    verify(mockGcsUtil).create(any(GcsPath.class), anyString());
    verifyNoMoreInteractions(mockGcsUtil);
    assertThat(target.getName(), RegexMatcher.matches("folder-" + HASH_PATTERN + ".jar"));
    assertThat(target.getLocation(), equalTo(STAGING_PATH + target.getName()));
    assertNull(new ZipInputStream(Channels.newInputStream(pipe.source())).getNextEntry());
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) GcsPath(org.apache.beam.sdk.util.gcsfs.GcsPath) FileNotFoundException(java.io.FileNotFoundException) Pipe(java.nio.channels.Pipe) File(java.io.File) DataflowPackage(com.google.api.services.dataflow.model.DataflowPackage) Test(org.junit.Test)

Example 10 with Pipe

use of java.nio.channels.Pipe in project beam by apache.

the class PackageUtilTest method testPackageUploadWithExplicitPackageName.

@Test
public void testPackageUploadWithExplicitPackageName() throws Exception {
    Pipe pipe = Pipe.open();
    File tmpFile = makeFileWithContents("file.txt", "This is a test!");
    final String overriddenName = "alias.txt";
    when(mockGcsUtil.getObjects(anyListOf(GcsPath.class))).thenReturn(ImmutableList.of(StorageObjectOrIOException.create(new FileNotFoundException("some/path"))));
    when(mockGcsUtil.create(any(GcsPath.class), anyString())).thenReturn(pipe.sink());
    List<DataflowPackage> targets = PackageUtil.stageClasspathElements(ImmutableList.of(overriddenName + "=" + tmpFile.getAbsolutePath()), STAGING_PATH, createOptions);
    DataflowPackage target = Iterables.getOnlyElement(targets);
    verify(mockGcsUtil).getObjects(anyListOf(GcsPath.class));
    verify(mockGcsUtil).create(any(GcsPath.class), anyString());
    verifyNoMoreInteractions(mockGcsUtil);
    assertThat(target.getName(), equalTo(overriddenName));
    assertThat(target.getLocation(), RegexMatcher.matches(STAGING_PATH + "file-" + HASH_PATTERN + ".txt"));
}
Also used : GcsPath(org.apache.beam.sdk.util.gcsfs.GcsPath) FileNotFoundException(java.io.FileNotFoundException) Pipe(java.nio.channels.Pipe) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) DataflowPackage(com.google.api.services.dataflow.model.DataflowPackage) Test(org.junit.Test)

Aggregations

Pipe (java.nio.channels.Pipe)21 Test (org.junit.Test)7 File (java.io.File)6 GcsPath (org.apache.beam.sdk.util.gcsfs.GcsPath)6 FileNotFoundException (java.io.FileNotFoundException)5 DataflowPackage (com.google.api.services.dataflow.model.DataflowPackage)3 DbusEventAppender (com.linkedin.databus.core.test.DbusEventAppender)3 DbusEventBufferReader (com.linkedin.databus.core.test.DbusEventBufferReader)3 DbusEventGenerator (com.linkedin.databus.core.test.DbusEventGenerator)3 UncaughtExceptionTrackingThread (com.linkedin.databus.core.util.UncaughtExceptionTrackingThread)3 ArrayList (java.util.ArrayList)3 Vector (java.util.Vector)3 Matchers.anyString (org.mockito.Matchers.anyString)3 DatabusV2ConsumerRegistration (com.linkedin.databus.client.consumer.DatabusV2ConsumerRegistration)2 MultiConsumerCallback (com.linkedin.databus.client.consumer.MultiConsumerCallback)2 SelectingDatabusCombinedConsumer (com.linkedin.databus.client.consumer.SelectingDatabusCombinedConsumer)2 StreamConsumerCallbackFactory (com.linkedin.databus.client.consumer.StreamConsumerCallbackFactory)2 ConsumerCallbackStats (com.linkedin.databus.client.pub.mbean.ConsumerCallbackStats)2 UnifiedClientStats (com.linkedin.databus.client.pub.mbean.UnifiedClientStats)2 Checkpoint (com.linkedin.databus.core.Checkpoint)2