private void stageAndCreateRetrievalService(Map<String, byte[]> artifacts) throws Exception { List<StagedFile> artifactFiles = new ArrayList<>(); for (Map.Entry<String, byte[]> artifact : artifacts.entrySet()) { File artifactFile = tmp.newFile(artifact.getKey()); Files.write(artifactFile.toPath(), artifact.getValue()); artifactFiles.add(StagedFile.of(artifactFile, artifactFile.getName())); } String stagingSessionToken = "token"; ArtifactServiceStager stager = ArtifactServiceStager.overChannel( InProcessChannelBuilder.forName(stagerServer.getApiServiceDescriptor().getUrl()) .build()); stager.stage(stagingSessionToken, artifactFiles); retrievalServer = GrpcFnServer.allocatePortAndCreateFor( LocalFileSystemArtifactRetrievalService.forRootDirectory(root), serverFactory); retrievalStub = ArtifactRetrievalServiceGrpc.newStub( InProcessChannelBuilder.forName(retrievalServer.getApiServiceDescriptor().getUrl()) .build()); }
@Before public void setup() throws Exception { service = ReferenceRunnerJobService.create(serverFactory) .withStagingPathSupplier(() -> runnerTemp.getRoot().toPath()); server = GrpcFnServer.allocatePortAndCreateFor(service, serverFactory); stub = JobServiceGrpc.newBlockingStub( InProcessChannelBuilder.forName(server.getApiServiceDescriptor().getUrl()).build()); }
@Test public void testPrepareJob() throws Exception { PrepareJobResponse response = stub.prepare( PrepareJobRequest.newBuilder() .setPipelineOptions(Struct.getDefaultInstance()) .setPipeline(Pipeline.getDefaultInstance()) .setJobName("myJobName") .build()); ApiServiceDescriptor stagingEndpoint = response.getArtifactStagingEndpoint(); ArtifactServiceStager stager = ArtifactServiceStager.overChannel( InProcessChannelBuilder.forName(stagingEndpoint.getUrl()).build()); String stagingSessionToken = "token"; File foo = writeTempFile("foo", "foo, bar, baz".getBytes(UTF_8)); File bar = writeTempFile("spam", "spam, ham, eggs".getBytes(UTF_8)); stager.stage( stagingSessionToken, ImmutableList.of(StagedFile.of(foo, foo.getName()), StagedFile.of(bar, bar.getName()))); List<byte[]> tempDirFiles = readFlattenedFiles(runnerTemp.getRoot()); assertThat( tempDirFiles, hasItems( arrayEquals(Files.readAllBytes(foo.toPath())), arrayEquals(Files.readAllBytes(bar.toPath())))); // TODO: 'run' the job with some sort of noop backend, to verify state is cleaned up. }
@Before public void setup() throws IOException { stager = ArtifactServiceStager.overChannel( InProcessChannelBuilder.forName("service_stager").build(), 6); service = new InMemoryArtifactStagerService(); server = InProcessServerBuilder.forName("service_stager") .directExecutor() .addService(service) .build() .start(); }
@Before public void setup() throws Exception { stager = LocalFileSystemArtifactStagerService.forRootDirectory(temporaryFolder.newFolder()); server = InProcessServerBuilder.forName("fs_stager") .directExecutor() .addService(stager) .build() .start(); stub = ArtifactStagingServiceGrpc.newStub( InProcessChannelBuilder.forName("fs_stager").usePlaintext().build()); }