Search in sources :

Example 56 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class LoggingClientTest method writeLogEntriesExceptionTest.

@Test
@SuppressWarnings("all")
public void writeLogEntriesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockLoggingServiceV2.addException(exception);
    try {
        LogNameOneof logName = LogNameOneof.from(LogName.create("[PROJECT]", "[LOG]"));
        MonitoredResource resource = MonitoredResource.newBuilder().build();
        Map<String, String> labels = new HashMap<>();
        List<LogEntry> entries = new ArrayList<>();
        client.writeLogEntries(logName, resource, labels, entries);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : LogNameOneof(com.google.logging.v2.LogNameOneof) HashMap(java.util.HashMap) StatusRuntimeException(io.grpc.StatusRuntimeException) ArrayList(java.util.ArrayList) MonitoredResource(com.google.api.MonitoredResource) LogEntry(com.google.logging.v2.LogEntry) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 57 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class MetricsClientTest method listLogMetricsExceptionTest.

@Test
@SuppressWarnings("all")
public void listLogMetricsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricsServiceV2.addException(exception);
    try {
        ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
        client.listLogMetrics(parent);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : ParentNameOneof(com.google.logging.v2.ParentNameOneof) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 58 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class TraceServiceClientTest method getTraceExceptionTest.

@Test
@SuppressWarnings("all")
public void getTraceExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockTraceService.addException(exception);
    try {
        String projectId = "projectId-1969970175";
        String traceId = "traceId1270300245";
        client.getTrace(projectId, traceId);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 59 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project google-cloud-java by GoogleCloudPlatform.

the class TraceServiceClientTest method patchTracesExceptionTest.

@Test
@SuppressWarnings("all")
public void patchTracesExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockTraceService.addException(exception);
    try {
        String projectId = "projectId-1969970175";
        Traces traces = Traces.newBuilder().build();
        client.patchTraces(projectId, traces);
        Assert.fail("No exception raised");
    } catch (ApiException e) {
        Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
    }
}
Also used : Traces(com.google.devtools.cloudtrace.v1.Traces) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 60 with StatusRuntimeException

use of io.grpc.StatusRuntimeException in project grakn by graknlabs.

the class GraqlConsole method start.

public static boolean start(GraqlShellOptions options, SessionProvider sessionProvider, String historyFile, PrintStream sout, PrintStream serr) throws InterruptedException, IOException {
    List<String> queries = null;
    // ------- Check option  ------------------------
    String query = options.getQuery();
    // This is a best-effort guess as to whether the user has made a mistake, without parsing the query
    if (query != null) {
        queries = ImmutableList.of(query);
        if (!query.contains("$") && query.trim().startsWith("match")) {
            serr.println(ErrorMessage.NO_VARIABLE_IN_QUERY.getMessage());
        }
    }
    // Print usage message if requested or if invalid arguments provided
    if (options.displayHelp()) {
        options.printUsage(sout);
        return true;
    }
    if (options.displayVersion()) {
        sout.println(GraknVersion.VERSION);
        return true;
    }
    // ------- Check option  ------------------------
    Path path = options.getBatchLoadPath();
    if (path != null) {
        Keyspace keyspace = options.getKeyspace();
        SimpleURI location = options.getUri();
        SimpleURI httpUri = location != null ? location : Grakn.DEFAULT_URI;
        try {
            BatchLoader.sendBatchRequest(httpUri, keyspace, path, sout, serr);
        } catch (Exception e) {
            sout.println("Batch failed \n" + CommonUtil.simplifyExceptionMessage(e));
            return false;
        }
        return true;
    }
    // --------   If no option set we start GraqlShell   ----------
    OutputFormat outputFormat = options.getOutputFormat();
    boolean infer = options.shouldInfer();
    ConsoleReader console = new ConsoleReader(System.in, sout);
    GraknSession session = sessionProvider.getSession(options, console);
    try (GraqlShell shell = new GraqlShell(historyFile, session, console, serr, outputFormat, infer)) {
        List<Path> filePaths = options.getFiles();
        if (filePaths != null) {
            queries = loadQueries(filePaths);
        }
        // Start shell
        shell.start(queries);
        return !shell.errorOccurred();
    } catch (StatusRuntimeException e) {
        if (e.getStatus().getCode().equals(Status.Code.UNAVAILABLE)) {
            serr.println(ErrorMessage.COULD_NOT_CONNECT.getMessage());
            return false;
        } else {
            throw e;
        }
    }
}
Also used : Path(java.nio.file.Path) ConsoleReader(jline.console.ConsoleReader) SimpleURI(ai.grakn.util.SimpleURI) GraknSession(ai.grakn.GraknSession) IOException(java.io.IOException) StatusRuntimeException(io.grpc.StatusRuntimeException) Keyspace(ai.grakn.Keyspace) StatusRuntimeException(io.grpc.StatusRuntimeException)

Aggregations

StatusRuntimeException (io.grpc.StatusRuntimeException)131 Test (org.junit.Test)110 ApiException (com.google.api.gax.grpc.ApiException)74 ByteString (com.google.protobuf.ByteString)12 Status (io.grpc.Status)12 ArrayList (java.util.ArrayList)11 Metadata (io.grpc.Metadata)10 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ProjectName (com.google.monitoring.v3.ProjectName)6 TopicName (com.google.pubsub.v1.TopicName)6 StreamObserver (io.grpc.stub.StreamObserver)6 ByteArrayInputStream (java.io.ByteArrayInputStream)6 Document (com.google.cloud.language.v1beta2.Document)5 ParentNameOneof (com.google.logging.v2.ParentNameOneof)5 IOException (java.io.IOException)5 ExecutionException (java.util.concurrent.ExecutionException)5 Document (com.google.cloud.language.v1.Document)4 EncodingType (com.google.cloud.language.v1beta2.EncodingType)4 HelloReply (io.grpc.examples.helloworld.HelloReply)4 HelloRequest (io.grpc.examples.helloworld.HelloRequest)4