public Result getResult() throws StateRestApiException, OtherMasterIndexException {
        if (failure != null) {
            if (failure instanceof OtherMasterIndexException) {
                throw (OtherMasterIndexException) failure;
            } else {
                throw (StateRestApiException) failure;
            }
        }
        if (!isCompleted()) {
            throw new InternalFailure("Attempt to fetch result before it has been calculated");
        }
        if (!resultSet) {
            throw new InternalFailure("Expected result to be set at this point.");
        }
        return result;
    }
@Test
    void testGetResultBeforeCompletion() {
        Request<String> r = new Request<>(Request.MasterState.MUST_BE_MASTER) {
            @Override
            public String calculateResult(Context context) {
                return "foo";
            }
        };
        try {
            r.getResult();
            fail();
        } catch (InternalFailure e) {
        } catch (Exception e) {
            fail();
        }
        r.notifyCompleted();
        try {
            r.getResult();
            fail();
        } catch (InternalFailure e) {
        } catch (Exception e) {
            fail();
        }
    }