aboutsummaryrefslogtreecommitdiffstats
path: root/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/task/util/process/TestChildProcess2.java
blob: 6decca64c8652bcff23c0ad519e53a1889c69033 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.node.admin.task.util.process;

import java.util.Optional;

/**
 * @author hakonhall
 */
public class TestChildProcess2 implements ChildProcess2 {
    private final int exitCode;
    private final String output;
    private Optional<RuntimeException> exceptionToThrowInWaitForTermination = Optional.empty();
    private boolean closeCalled = false;

    public TestChildProcess2(int exitCode, String output) {
        this.exitCode = exitCode;
        this.output = output;
    }

    public void throwInWaitForTermination(RuntimeException e) {
        this.exceptionToThrowInWaitForTermination = Optional.of(e);
    }

    @Override
    public void waitForTermination() {
        if (exceptionToThrowInWaitForTermination.isPresent()) {
            throw exceptionToThrowInWaitForTermination.get();
        }
    }

    @Override
    public int exitCode() {
        return exitCode;
    }

    @Override
    public String getOutput() {
        return output;
    }

    @Override
    public void close() {
        if (closeCalled) {
            throw new IllegalStateException("close already called");
        }
        closeCalled = true;
    }

    public boolean closeCalled() {
        return closeCalled;
    }
}