Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ private static int waitForReplicaRoutedRead(
private static void waitForReplicaRoutedStrongRead(
DatabaseClient client, SharedBackendReplicaHarness harness, int expectedReplicaIndex)
throws InterruptedException {
long deadlineNanos = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
long deadlineNanos = System.nanoTime() + TimeUnit.SECONDS.toNanos(30);
while (System.nanoTime() < deadlineNanos) {
harness.clearRequests();
boolean sawRow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.spanner.admin.database.v1.BackupScheduleName;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -29,6 +30,11 @@ public class CreateFullBackupScheduleSampleIT extends SampleTestBaseV2 {
// Default instance and given db should exist for tests to pass.
private static String databaseId = System.getProperty("spanner.sample.database", "mysample");

@Before
public void cleanUpPreExistingBackupSchedules() {
cleanUpPreExistingBackupSchedules(instanceId, databaseId);
}

@Test
public void testCreateFullBackupScheduleSample() throws Exception {
String backupScheduleId = String.format("schedule-%s", UUID.randomUUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.spanner.admin.database.v1.BackupScheduleName;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -29,6 +30,11 @@ public class CreateIncrementalBackupScheduleSampleIT extends SampleTestBaseV2 {
// Default instance and given db should exist for tests to pass.
private static String databaseId = System.getProperty("spanner.sample.database", "mysample");

@Before
public void cleanUpPreExistingBackupSchedules() {
cleanUpPreExistingBackupSchedules(multiRegionalInstanceId, databaseId);
}

@Test
public void testCreateIncrementalBackupScheduleSample() throws Exception {
String backupScheduleId = String.format("schedule-%s", UUID.randomUUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.spanner.admin.database.v1.BackupScheduleName;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -29,6 +30,11 @@ public class DeleteBackupScheduleSampleIT extends SampleTestBaseV2 {
// Default instance and given db should exist for tests to pass.
private static String databaseId = System.getProperty("spanner.sample.database", "mysample");

@Before
public void cleanUpPreExistingBackupSchedules() {
cleanUpPreExistingBackupSchedules(instanceId, databaseId);
}

@Test
public void testDeleteBackupScheduleSample() throws Exception {
String backupScheduleId = String.format("schedule-%s", UUID.randomUUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.spanner.admin.database.v1.BackupScheduleName;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -29,6 +30,11 @@ public class GetBackupScheduleSampleIT extends SampleTestBaseV2 {
// Default instance and given db should exist for tests to pass.
private static String databaseId = System.getProperty("spanner.sample.database", "mysample");

@Before
public void cleanUpPreExistingBackupSchedules() {
cleanUpPreExistingBackupSchedules(instanceId, databaseId);
}

@Test
public void testGetBackupScheduleSample() throws Exception {
String backupScheduleId = String.format("schedule-%s", UUID.randomUUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.spanner.admin.database.v1.BackupScheduleName;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -29,6 +30,11 @@ public class ListBackupSchedulesSampleIT extends SampleTestBaseV2 {
// Default instance and given db should exist for tests to pass.
private static String databaseId = System.getProperty("spanner.sample.database", "mysample");

@Before
public void cleanUpPreExistingBackupSchedules() {
cleanUpPreExistingBackupSchedules(instanceId, databaseId);
}

@Test
public void testListBackupSchedulesSample() throws Exception {
String backupScheduleId1 = String.format("schedule-%s", UUID.randomUUID());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.cloud.spanner.admin.database.v1.DatabaseAdminSettings;
import com.google.cloud.spanner.admin.instance.v1.InstanceAdminClient;
import com.google.cloud.spanner.admin.instance.v1.InstanceAdminSettings;
import com.google.spanner.admin.database.v1.BackupSchedule;
import com.google.spanner.admin.database.v1.DatabaseDialect;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -180,4 +181,26 @@ static String getCreateDatabaseStatement(
return "CREATE DATABASE \"" + databaseName + "\"";
}
}

protected static void cleanUpPreExistingBackupSchedules(
final String targetInstanceId, final String targetDatabaseId) {
try {
if (targetInstanceId == null || targetDatabaseId == null || databaseAdminClient == null) {
return;
}
DatabaseAdminClient dbAdminClient = databaseAdminClient;
for (BackupSchedule schedule :
dbAdminClient
.listBackupSchedules(getDatabaseName(projectId, targetInstanceId, targetDatabaseId))
.iterateAll()) {
try {
dbAdminClient.deleteBackupSchedule(schedule.getName());
} catch (Exception ignored) {
// Ignore errors if schedule was already deleted or is in use
}
}
} catch (Exception e) {
System.err.println("Warning: failed pre-test schedule cleanup: " + e.getMessage());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import com.google.spanner.admin.database.v1.BackupScheduleName;
import java.util.UUID;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
Expand All @@ -29,6 +30,11 @@ public class UpdateBackupScheduleSampleIT extends SampleTestBaseV2 {
// Default instance and given db should exist for tests to pass.
private static String databaseId = System.getProperty("spanner.sample.database", "mysample");

@Before
public void cleanUpPreExistingBackupSchedules() {
cleanUpPreExistingBackupSchedules(instanceId, databaseId);
}

@Test
public void testUpdateBackupScheduleSample() throws Exception {
String backupScheduleId = String.format("schedule-%s", UUID.randomUUID());
Expand Down
Loading