/** * Fetches current sink's latest information. Returns {@code null} if the sink does not exist. * * <p>Example of getting the sink's latest information. * * <pre>{@code * Sink latestSink = sink.reload(); * if (latestSink == null) { * // the sink was not found * } * }</pre> * * @return a {@code Sink} object with latest information or {@code null} if not found * @throws LoggingException upon failure */ public Sink reload() { return logging.getSink(getName()); }
/** * Deletes this sink. * * <p>Example of deleting the sink. * * <pre>{@code * boolean deleted = sink.delete(); * if (deleted) { * // the sink was deleted * } else { * // the sink was not found * } * }</pre> * * @return {@code true} if the sink was deleted, {@code false} if it was not found * @throws LoggingException upon failure */ public boolean delete() { return logging.deleteSink(getName()); }
/** * Sends a request to fetch current sink's latest information. This method returns a {@code * ApiFuture} object to consume the result. {@link ApiFuture#get()} returns a {@code Sink} object * with latest information or {@code null} if not found. * * <p>Example of asynchronously getting the sink's latest information. * * <pre>{@code * ApiFuture<Sink> future = sink.reloadAsync(); * // ... * Sink latestSink = future.get(); * if (latestSink == null) { * // the sink was not found * } * }</pre> * * @throws LoggingException upon failure */ public ApiFuture<Sink> reloadAsync() { return logging.getSinkAsync(getName()); }
/** * Sends a request for deleting this sink. This method returns a {@code ApiFuture} object to * consume the result. {@link ApiFuture#get()} returns {@code true} if the sink was deleted, * {@code false} if it was not found. * * <p>Example of asynchronously deleting the sink. * * <pre>{@code * ApiFuture<Boolean> future = sink.deleteAsync(); * // ... * boolean deleted = future.get(); * if (deleted) { * // the sink was deleted * } else { * // the sink was not found * } * }</pre> * * @throws LoggingException upon failure */ public ApiFuture<Boolean> deleteAsync() { return logging.deleteSinkAsync(getName()); }
private void compareSink(Sink expected, Sink value) { assertEquals(expected, value); assertEquals(expected.getName(), value.getName()); assertEquals(expected.getDestination(), value.getDestination()); assertEquals(expected.getFilter(), value.getFilter()); assertEquals(expected.getVersionFormat(), value.getVersionFormat()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } }
@Test public void testBuilder() { initializeExpectedSink(2); replay(logging); Sink builtSink = expectedSink .toBuilder() .setName(NEW_NAME) .setFilter(NEW_FILTER) .setDestination(DATASET_DESTINATION) .setVersionFormat(NEW_VERSION) .build(); assertEquals(NEW_NAME, builtSink.getName()); assertEquals(DATASET_DESTINATION, builtSink.getDestination()); assertEquals(NEW_FILTER, builtSink.getFilter()); assertEquals(NEW_VERSION, builtSink.getVersionFormat()); }
@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()); }
/** * Fetches current sink's latest information. Returns {@code null} if the sink does not exist. * * <p>Example of getting the sink's latest information. * * <pre>{@code * Sink latestSink = sink.reload(); * if (latestSink == null) { * // the sink was not found * } * }</pre> * * @return a {@code Sink} object with latest information or {@code null} if not found * @throws LoggingException upon failure */ public Sink reload() { return logging.getSink(getName()); }
/** * Deletes this sink. * * <p>Example of deleting the sink. * * <pre>{@code * boolean deleted = sink.delete(); * if (deleted) { * // the sink was deleted * } else { * // the sink was not found * } * }</pre> * * @return {@code true} if the sink was deleted, {@code false} if it was not found * @throws LoggingException upon failure */ public boolean delete() { return logging.deleteSink(getName()); }
/** * Sends a request to fetch current sink's latest information. This method returns a {@code * ApiFuture} object to consume the result. {@link ApiFuture#get()} returns a {@code Sink} object * with latest information or {@code null} if not found. * * <p>Example of asynchronously getting the sink's latest information. * * <pre>{@code * ApiFuture<Sink> future = sink.reloadAsync(); * // ... * Sink latestSink = future.get(); * if (latestSink == null) { * // the sink was not found * } * }</pre> * * @throws LoggingException upon failure */ public ApiFuture<Sink> reloadAsync() { return logging.getSinkAsync(getName()); }
/** * Sends a request for deleting this sink. This method returns a {@code ApiFuture} object to * consume the result. {@link ApiFuture#get()} returns {@code true} if the sink was deleted, * {@code false} if it was not found. * * <p>Example of asynchronously deleting the sink. * * <pre>{@code * ApiFuture<Boolean> future = sink.deleteAsync(); * // ... * boolean deleted = future.get(); * if (deleted) { * // the sink was deleted * } else { * // the sink was not found * } * }</pre> * * @throws LoggingException upon failure */ public ApiFuture<Boolean> deleteAsync() { return logging.deleteSinkAsync(getName()); }