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());
}
}
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());
}
}
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());
}
}
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());
}
}
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;
}
}
}
Aggregations