@Test public void testListMetrics() throws InterruptedException { String firstName = formatForTest("test-list-metrics-1"); String secondName = formatForTest("test-list-metrics-2"); Metric firstMetric = logging().create(MetricInfo.of(firstName, "severity>=ERROR")); Metric secondMetric = logging().create(MetricInfo.of(secondName, "severity>=ERROR")); Logging.ListOption[] options = {Logging.ListOption.pageSize(1)}; Page<Metric> metricPage = logging().listMetrics(options); Set<Metric> metrics = Sets.newHashSet(metricPage.iterateAll()); while (!metrics.contains(firstMetric) || !metrics.contains(secondMetric)) { Thread.sleep(500); metrics = Sets.newHashSet(logging().listMetrics(options).iterateAll()); } firstMetric.delete(); secondMetric.delete(); }
@Test public void testListSinks() throws InterruptedException { String firstName = formatForTest("test-list-sinks-1"); String secondName = formatForTest("test-list-sinks-2"); Sink firstSink = logging().create(SinkInfo.of(firstName, DatasetDestination.of("dataset"))); Sink secondSink = logging().create(SinkInfo.of(secondName, DatasetDestination.of("dataset"))); Logging.ListOption[] options = {Logging.ListOption.pageSize(1)}; Page<Sink> sinkPage = logging().listSinks(options); Set<Sink> sinks = Sets.newHashSet(sinkPage.iterateAll()); while (!sinks.contains(firstSink) || !sinks.contains(secondSink)) { Thread.sleep(500); sinks = Sets.newHashSet(logging().listSinks(options).iterateAll()); } firstSink.delete(); secondSink.delete(); }
@Test public void testListMonitoredResourceDescriptors() { Iterator<MonitoredResourceDescriptor> iterator = logging() .listMonitoredResourceDescriptors(Logging.ListOption.pageSize(100)) .iterateAll() .iterator(); int count = 0; while (iterator.hasNext()) { assertNotNull(iterator.next().getType()); count += 1; } assertTrue(count > 0); }
@Test public void testDeleteNonExistingLog() { String logId = formatForTest("test-delete-non-existing-log"); assertFalse(logging().deleteLog(logId)); }
@Test public void testLoggingHandler() throws InterruptedException { String logId = formatForTest("test-logging-handler"); LoggingOptions options = logging().getOptions(); LogName logName = ProjectLogName.of(options.getProjectId(), logId); LoggingHandler handler = new LoggingHandler(logId, options); String filter = createEqualityFilter("logName", logName); Iterator<LogEntry> iterator = logging().listLogEntries(EntryListOption.filter(filter)).iterateAll().iterator(); while (!iterator.hasNext()) { Thread.sleep(500L); iterator = logging().listLogEntries(EntryListOption.filter(filter)).iterateAll().iterator(); assertThat(iterator.hasNext()).isFalse(); logger.removeHandler(handler); logging().deleteLog(logId);
@Test public void testUpdateNonExistingSink() { String name = formatForTest("test-update-non-existing-sink"); SinkInfo sinkInfo = SinkInfo.newBuilder(name, DatasetDestination.of("dataset")) .setFilter("severity>=ERROR") .setVersionFormat(SinkInfo.VersionFormat.V2) .build(); assertNull(logging().getSink(name)); thrown.expect(LoggingException.class); thrown.expectMessage("NOT_FOUND"); logging().update(sinkInfo); }
@Test public void testSyncLoggingHandler() throws InterruptedException { String logId = formatForTest("test-sync-logging-handler"); LoggingOptions options = logging().getOptions(); LogName logName = ProjectLogName.of(options.getProjectId(), logId); MonitoredResource resource = String filter = createEqualityFilter("logName", logName); Iterator<LogEntry> iterator = logging().listLogEntries(EntryListOption.filter(filter)).iterateAll().iterator(); while (!iterator.hasNext()) { Thread.sleep(500L); iterator = logging().listLogEntries(EntryListOption.filter(filter)).iterateAll().iterator(); assertFalse(iterator.hasNext()); logger.removeHandler(handler); logging().deleteLog(logId);
@Test public void testUpdateNonExistingMetric() { String name = formatForTest("test-update-non-existing-metric"); MetricInfo metricInfo = MetricInfo.newBuilder(name, "severity>=ERROR").setDescription("description").build(); assertNull(logging().getMetric(name)); Metric metric = logging().update(metricInfo); assertEquals(name, metric.getName()); assertEquals("severity>=ERROR", metric.getFilter()); assertEquals("description", metric.getDescription()); assertTrue(metric.delete()); }
@Test public void testWriteAndListLogEntries() throws InterruptedException { String logId = formatForTest("test-write-log-entries-log"); LoggingOptions loggingOptions = logging().getOptions(); LogName logName = ProjectLogName.of(loggingOptions.getProjectId(), logId); StringPayload firstPayload = StringPayload.of("stringPayload"); .setResource(MonitoredResource.newBuilder("cloudsql_database").build()) .build(); logging().write(ImmutableList.of(firstEntry)); logging().write(ImmutableList.of(secondEntry)); logging().flush(); String filter = createEqualityFilter("logName", logName); EntryListOption[] options = {EntryListOption.filter(filter), EntryListOption.pageSize(1)}; Page<LogEntry> page = logging().listLogEntries(options); while (Iterators.size(page.iterateAll().iterator()) < 2) { Thread.sleep(500); page = logging().listLogEntries(options); EntryListOption.sortOrder(SortingField.TIMESTAMP, SortingOrder.DESCENDING) }; page = logging().listLogEntries(options); while (Iterators.size(page.iterateAll().iterator()) < 2) { Thread.sleep(500); page = logging().listLogEntries(options); while (!deleted && deleteAttempts < allowedDeleteAttempts) { Thread.sleep(1000); deleted = logging().deleteLog(logId); deleteAttempts++;
@Test public void testCreateGetUpdateAndDeleteSink() { String name = formatForTest("test-create-get-update-sink"); SinkInfo sinkInfo = SinkInfo.newBuilder(name, DatasetDestination.of("dataset")) .setFilter("severity>=ERROR") .setVersionFormat(SinkInfo.VersionFormat.V2) .build(); Sink sink = logging().create(sinkInfo); assertEquals(name, sink.getName()); assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); assertEquals("severity>=ERROR", sink.getFilter()); DatasetDestination datasetDestination = sink.getDestination(); assertEquals(logging().getOptions().getProjectId(), datasetDestination.getProject()); assertEquals("dataset", datasetDestination.getDataset()); assertEquals(sink, logging().getSink(name)); sink = sink.toBuilder().setFilter("severity<=ERROR").build().update(); assertEquals(name, sink.getName()); assertEquals(SinkInfo.VersionFormat.V2, sink.getVersionFormat()); assertEquals("severity<=ERROR", sink.getFilter()); assertTrue(sink.delete()); assertFalse(sink.delete()); }
@Test public void testCreateGetUpdateAndDeleteMetric() { String name = formatForTest("test-create-get-update-metric"); MetricInfo metricInfo = MetricInfo.newBuilder(name, "severity>=ERROR").setDescription("description").build(); Metric metric = logging().create(metricInfo); assertEquals(name, metric.getName()); assertEquals("severity>=ERROR", metric.getFilter()); assertEquals("description", metric.getDescription()); assertEquals(metric, logging().getMetric(name)); metric = metric .toBuilder() .setDescription("newDescription") .setFilter("severity>=WARNING") .build() .update(); assertEquals(name, metric.getName()); assertEquals("severity>=WARNING", metric.getFilter()); assertEquals("newDescription", metric.getDescription()); assertTrue(metric.delete()); assertFalse(metric.delete()); }