Search in sources :

Example 46 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.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 47 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.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 48 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.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 49 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.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 50 with StatusRuntimeException

use of org.apache.beam.vendor.grpc.v1p43p2.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)240 Test (org.junit.Test)164 ApiException (com.google.api.gax.grpc.ApiException)74 Status (io.grpc.Status)25 StreamObserver (io.grpc.stub.StreamObserver)20 ByteString (com.google.protobuf.ByteString)18 ArrayList (java.util.ArrayList)18 Metadata (io.grpc.Metadata)14 SimpleServiceGrpc (io.grpc.testing.protobuf.SimpleServiceGrpc)13 ExecutionException (java.util.concurrent.ExecutionException)12 JanusGraphGrpcServerBaseTest (org.janusgraph.graphdb.grpc.JanusGraphGrpcServerBaseTest)12 Test (org.junit.jupiter.api.Test)12 SubscriptionName (com.google.pubsub.v1.SubscriptionName)9 ManagedChannel (io.grpc.ManagedChannel)9 StatusRuntimeException (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.StatusRuntimeException)8 BStruct (org.ballerinalang.model.values.BStruct)8 SimpleRequest (io.grpc.testing.integration.Messages.SimpleRequest)7 ChannelCredentials (io.grpc.ChannelCredentials)6 ServerCredentials (io.grpc.ServerCredentials)6 TlsChannelCredentials (io.grpc.TlsChannelCredentials)6