Search in sources :

Example 1 with Response

use of com.hederahashgraph.api.proto.java.Response in project hedera-services by hashgraph.

the class QueryResponseHelper method respondWithMetrics.

private void respondWithMetrics(Query query, StreamObserver<Response> observer, AnswerService answer, Runnable incReceivedCount, Runnable incAnsweredCount) {
    if (log.isDebugEnabled()) {
        log.debug(ALL_QUERIES_MARKER, "Received query: {}", query);
    }
    Response response;
    incReceivedCount.run();
    try {
        response = answerFlow.satisfyUsing(answer, query);
    } catch (Exception surprising) {
        log.warn("Query flow unable to satisfy query {}!", query, surprising);
        response = answer.responseGiven(query, EMPTY_VIEW, FAIL_INVALID, 0L);
    }
    observer.onNext(response);
    observer.onCompleted();
    if (answer.extractValidityFrom(response) == OK) {
        incAnsweredCount.run();
    }
}
Also used : Response(com.hederahashgraph.api.proto.java.Response)

Example 2 with Response

use of com.hederahashgraph.api.proto.java.Response in project hedera-services by hashgraph.

the class GetFileContentsAnswerTest method getsCostAnswerResponse.

@Test
void getsCostAnswerResponse() throws Throwable {
    // setup:
    Query query = validQuery(COST_ANSWER, fee, target);
    // when:
    Response response = subject.responseGiven(query, view, OK, fee);
    // then:
    assertTrue(response.hasFileGetContents());
    assertEquals(asFile(target), response.getFileGetContents().getFileContents().getFileID());
    assertEquals(OK, response.getFileGetContents().getHeader().getNodeTransactionPrecheckCode());
    assertEquals(COST_ANSWER, response.getFileGetContents().getHeader().getResponseType());
    assertEquals(fee, response.getFileGetContents().getHeader().getCost());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) FileGetContentsResponse(com.hederahashgraph.api.proto.java.FileGetContentsResponse) FileGetInfoResponse(com.hederahashgraph.api.proto.java.FileGetInfoResponse) Query(com.hederahashgraph.api.proto.java.Query) FileGetContentsQuery(com.hederahashgraph.api.proto.java.FileGetContentsQuery) Test(org.junit.jupiter.api.Test)

Example 3 with Response

use of com.hederahashgraph.api.proto.java.Response in project hedera-services by hashgraph.

the class GetFileContentsAnswerTest method getsInvalidResponse.

@Test
void getsInvalidResponse() throws Throwable {
    // setup:
    Query query = validQuery(COST_ANSWER, fee, target);
    // when:
    Response response = subject.responseGiven(query, view, FILE_DELETED, fee);
    // then:
    assertTrue(response.hasFileGetContents());
    assertEquals(asFile(target), response.getFileGetContents().getFileContents().getFileID());
    assertEquals(FILE_DELETED, response.getFileGetContents().getHeader().getNodeTransactionPrecheckCode());
    assertEquals(COST_ANSWER, response.getFileGetContents().getHeader().getResponseType());
    assertEquals(fee, response.getFileGetContents().getHeader().getCost());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) FileGetContentsResponse(com.hederahashgraph.api.proto.java.FileGetContentsResponse) FileGetInfoResponse(com.hederahashgraph.api.proto.java.FileGetInfoResponse) Query(com.hederahashgraph.api.proto.java.Query) FileGetContentsQuery(com.hederahashgraph.api.proto.java.FileGetContentsQuery) Test(org.junit.jupiter.api.Test)

Example 4 with Response

use of com.hederahashgraph.api.proto.java.Response in project hedera-services by hashgraph.

the class GetFileInfoAnswerTest method getsCostAnswerResponse.

@Test
void getsCostAnswerResponse() throws Throwable {
    // setup:
    Query query = validQuery(COST_ANSWER, fee, target);
    // when:
    Response response = subject.responseGiven(query, view, OK, fee);
    // then:
    assertTrue(response.hasFileGetInfo());
    assertEquals(OK, response.getFileGetInfo().getHeader().getNodeTransactionPrecheckCode());
    assertEquals(COST_ANSWER, response.getFileGetInfo().getHeader().getResponseType());
    assertEquals(fee, response.getFileGetInfo().getHeader().getCost());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) FileGetInfoResponse(com.hederahashgraph.api.proto.java.FileGetInfoResponse) FileGetInfoQuery(com.hederahashgraph.api.proto.java.FileGetInfoQuery) Query(com.hederahashgraph.api.proto.java.Query) Test(org.junit.jupiter.api.Test)

Example 5 with Response

use of com.hederahashgraph.api.proto.java.Response in project hedera-services by hashgraph.

the class GetFileInfoAnswerTest method getsInvalidResponse.

@Test
void getsInvalidResponse() throws Throwable {
    // setup:
    Query query = validQuery(COST_ANSWER, fee, target);
    // when:
    Response response = subject.responseGiven(query, view, FILE_DELETED, fee);
    // then:
    assertTrue(response.hasFileGetInfo());
    assertEquals(FILE_DELETED, response.getFileGetInfo().getHeader().getNodeTransactionPrecheckCode());
    assertEquals(COST_ANSWER, response.getFileGetInfo().getHeader().getResponseType());
    assertEquals(fee, response.getFileGetInfo().getHeader().getCost());
}
Also used : Response(com.hederahashgraph.api.proto.java.Response) FileGetInfoResponse(com.hederahashgraph.api.proto.java.FileGetInfoResponse) FileGetInfoQuery(com.hederahashgraph.api.proto.java.FileGetInfoQuery) Query(com.hederahashgraph.api.proto.java.Query) Test(org.junit.jupiter.api.Test)

Aggregations

Response (com.hederahashgraph.api.proto.java.Response)114 Query (com.hederahashgraph.api.proto.java.Query)96 Test (org.junit.jupiter.api.Test)87 FileGetInfoResponse (com.hederahashgraph.api.proto.java.FileGetInfoResponse)9 ByteString (com.google.protobuf.ByteString)8 ContractCallLocalQuery (com.hederahashgraph.api.proto.java.ContractCallLocalQuery)8 TokenGetNftInfoQuery (com.hederahashgraph.api.proto.java.TokenGetNftInfoQuery)8 TokenGetNftInfoResponse (com.hederahashgraph.api.proto.java.TokenGetNftInfoResponse)8 TransactionGetReceiptResponse (com.hederahashgraph.api.proto.java.TransactionGetReceiptResponse)8 ContractCallLocalResponse (com.hederahashgraph.api.proto.java.ContractCallLocalResponse)7 ContractGetInfoQuery (com.hederahashgraph.api.proto.java.ContractGetInfoQuery)7 ContractGetInfoResponse (com.hederahashgraph.api.proto.java.ContractGetInfoResponse)7 NetworkGetExecutionTimeQuery (com.hederahashgraph.api.proto.java.NetworkGetExecutionTimeQuery)7 NetworkGetExecutionTimeResponse (com.hederahashgraph.api.proto.java.NetworkGetExecutionTimeResponse)7 ResponseCodeEnum (com.hederahashgraph.api.proto.java.ResponseCodeEnum)7 ScheduleGetInfoQuery (com.hederahashgraph.api.proto.java.ScheduleGetInfoQuery)7 ScheduleGetInfoResponse (com.hederahashgraph.api.proto.java.ScheduleGetInfoResponse)7 TokenGetInfoQuery (com.hederahashgraph.api.proto.java.TokenGetInfoQuery)7 TokenGetInfoResponse (com.hederahashgraph.api.proto.java.TokenGetInfoResponse)7 HashMap (java.util.HashMap)7