ConnectCommandRunner extends AbstractServerCommandRunner { @NotNull @Override public P4CommandRunner.QueryAnswer<GetJobSpecResult> getJobSpec( @NotNull OptionalClientServerConfig config) { return new QueryAnswerImpl<>(connectionManager.withConnection(config, (server) -> new GetJobSpecResult( config, new P4JobSpecImpl(cmd.getJobSpec(server)) ) )); } ConnectCommandRunner(
            @NotNull Project project,
            @NotNull ConnectionManager connectionManager); @Override void disconnect(@NotNull P4ServerName config); @NotNull @Override P4CommandRunner.QueryAnswer<AnnotateFileResult> getFileAnnotation(
            @NotNull ClientConfig config,
            @NotNull final AnnotateFileQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<DescribeChangelistResult> describeChangelist(
            @NotNull OptionalClientServerConfig config,
            @NotNull DescribeChangelistQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<GetJobSpecResult> getJobSpec(
            @NotNull OptionalClientServerConfig config); @NotNull @Override P4CommandRunner.QueryAnswer<ListOpenedFilesChangesResult> listOpenedFilesChanges(@NotNull ClientConfig config,
            @NotNull ListOpenedFilesChangesQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListClientsForUserResult> getClientsForUser(
            @NotNull OptionalClientServerConfig config,
            @NotNull ListClientsForUserQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListSubmittedChangelistsResult> listSubmittedChangelists(
            @NotNull final ClientConfig config, @NotNull final ListSubmittedChangelistsQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<GetFileContentsResult> getFileContents(
            @NotNull ClientConfig config,
            @NotNull final GetFileContentsQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListFileHistoryResult> listFilesHistory(
            @NotNull ClientConfig config,
            @NotNull final ListFileHistoryQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListFilesDetailsResult> listFilesDetails(
            @NotNull ClientConfig config,
            @NotNull final ListFilesDetailsQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListJobsResult> listJobs(
            @NotNull OptionalClientServerConfig config,
            @NotNull final ListJobsQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListLabelsResult> listLabels(
            @NotNull OptionalClientServerConfig config,
            @NotNull final ListLabelsQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<ListUsersResult> listUsers(
            @NotNull OptionalClientServerConfig config,
            @NotNull final ListUsersQuery query); @NotNull @Override P4CommandRunner.QueryAnswer<SwarmConfigResult> getSwarmConfig(
            @NotNull OptionalClientServerConfig config,
            @NotNull final SwarmConfigQuery query);  }
@ExtendWith(TemporaryFolderExtension.class) @Test void getJobSpec_CreateJob(TemporaryFolder tmpDir) throws IOException, InterruptedException { idea.useInlineThreading(null); final ServerConfig config = ServerConfig.createFrom( new MockConfigPart() .withServerName(server.getRshUrl()) .withUsername(server.getUser()) .withNoPassword() ); final MockP4RequestErrorHandler errorHandler = new MockP4RequestErrorHandler(); SimpleConnectionManager mgr = new SimpleConnectionManager( tmpDir.newFile("out"), 1000, "v1", errorHandler); ConnectCommandRunner runner = new ConnectCommandRunner(idea.getMockProject(), mgr); final CreateJobResult[] result = new CreateJobResult[1]; runner.getJobSpec(new OptionalClientServerConfig(config, null)) .mapActionAsync((jobSpec) -> runner.perform(new OptionalClientServerConfig(config, null), new CreateJobAction(createP4Job(config, jobSpec))) ) .whenCompleted((res) -> result[0] = res) .whenServerError(Assertions::fail) .waitForCompletion(5, TimeUnit.SECONDS); assertNotNull(result[0]); assertEmpty(errorHandler.getExceptions()); assertEmpty(errorHandler.getDisconnectExceptions()); assertSame(config, result[0].getServerConfig()); assertNotNull(result[0].getJob()); assertEquals(JOB_ID, result[0].getJob().getJobId()); assertNotNull(result[0].getJob().getDescription()); assertEquals(JOB_DESCRIPTION, result[0].getJob().getDescription().trim()); assertEquals(config.getUsername(), result[0].getJob().getRawDetails().get("User")); }
@ExtendWith(TemporaryFolderExtension.class) @Test void createJob_error(TemporaryFolder tmpDir) throws IOException { idea.useInlineThreading(null); final ServerConfig config = ServerConfig.createFrom( new MockConfigPart() .withServerName(server.getRshUrl()) .withUsername(server.getUser()) .withNoPassword() ); final MockP4RequestErrorHandler errorHandler = new MockP4RequestErrorHandler(); SimpleConnectionManager mgr = new SimpleConnectionManager( tmpDir.newFile("out"), 1000, "v1", errorHandler); ConnectCommandRunner runner = new ConnectCommandRunner(idea.getMockProject(), mgr); runner.getJobSpec(new OptionalClientServerConfig(config, null)) .mapActionAsync((jobSpec) -> runner.perform(new OptionalClientServerConfig(config, null), new CreateJobAction(new P4JobImpl("j", "x", null))) ) .whenCompleted((x) -> fail("Did not throw an error")) .whenServerError((ex) -> { assertNotNull(ex); assertThat(ex.getCause(), instanceOf(RequestException.class)); }); assertSize(1, errorHandler.getExceptions()); assertThat(errorHandler.getExceptions().get(0), instanceOf(RequestException.class)); }