diff --git a/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITSinkTest.java b/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITSinkTest.java index 1879860bf..fc50a6053 100644 --- a/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITSinkTest.java +++ b/google-cloud-logging/src/test/java/com/google/cloud/logging/it/ITSinkTest.java @@ -31,11 +31,29 @@ import com.google.cloud.logging.Sink; import com.google.cloud.logging.SinkInfo; import com.google.common.collect.Sets; +import java.util.Iterator; import java.util.Set; +import org.junit.BeforeClass; import org.junit.Test; public class ITSinkTest extends BaseSystemTest { + @BeforeClass + public static void setUp() { + // Cleanup all stucked sinks if any + Logging.ListOption[] options = {Logging.ListOption.pageSize(50)}; + Page sinkPage = logging.listSinks(options); + Iterator iterator = sinkPage.iterateAll().iterator(); + while (iterator.hasNext()) { + Sink sink = iterator.next(); + try { + sink.delete(); + } catch (Exception ex) { + System.err.println("ERROR: Failed to delete a " + sink.getName() + " sink, error: " + ex); + } + } + } + @Test public void testCreateGetUpdateAndDeleteSink() { String name = formatForTest("test-create-get-update-sink");