-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Update ChangeStreamDao to query different TVF for postgresSQL based on the change stream partition mode #36667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,10 +19,18 @@ | |
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertNull; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.any; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import com.google.auth.Credentials; | ||
| import com.google.cloud.Timestamp; | ||
| import com.google.cloud.spanner.DatabaseClient; | ||
| import com.google.cloud.spanner.Dialect; | ||
| import com.google.cloud.spanner.Options.RpcPriority; | ||
| import com.google.cloud.spanner.ReadOnlyTransaction; | ||
| import com.google.cloud.spanner.ResultSet; | ||
| import com.google.cloud.spanner.Statement; | ||
| import org.apache.beam.sdk.extensions.gcp.auth.TestCredential; | ||
| import org.apache.beam.sdk.extensions.gcp.options.GcpOptions; | ||
| import org.apache.beam.sdk.io.gcp.spanner.changestreams.MetadataSpannerConfigFactory; | ||
|
|
@@ -32,6 +40,7 @@ | |
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.junit.runners.JUnit4; | ||
| import org.mockito.Mockito; | ||
|
|
||
| @RunWith(JUnit4.class) | ||
| public class SpannerIOReadChangeStreamTest { | ||
|
|
@@ -120,7 +129,8 @@ public void testSetSpannerConfigCredential() { | |
|
|
||
| @Test | ||
| public void testWithDefaultCredential() { | ||
| // Get the default credential, without setting any credentials in the pipeline options or | ||
| // Get the default credential, without setting any credentials in the pipeline | ||
| // options or | ||
| // SpannerConfig. | ||
| Credentials defaultCredential = | ||
| testPipeline.getOptions().as(GcpOptions.class).getGcpCredential(); | ||
|
|
@@ -140,4 +150,53 @@ public void testWithDefaultCredential() { | |
| assertEquals(defaultCredential, changeStreamSpannerConfigWithCredential.getCredentials().get()); | ||
| assertEquals(defaultCredential, metadataSpannerConfigWithCredential.getCredentials().get()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFetchPartitionModeGoogleSql() { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can we parameterized the tests to have different combination among googlesql/postgresql vs immuatable/mutable/empty string ? |
||
| DatabaseClient databaseClient = Mockito.mock(DatabaseClient.class); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These lines are the same for all tests below, can they be refactored to avoid repeatition? Thanks. |
||
| ReadOnlyTransaction transaction = Mockito.mock(ReadOnlyTransaction.class); | ||
| ResultSet resultSet = Mockito.mock(ResultSet.class); | ||
|
|
||
| when(databaseClient.readOnlyTransaction()).thenReturn(transaction); | ||
| when(transaction.executeQuery(any(Statement.class))).thenReturn(resultSet); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If through mock, how the fetch option sql statement syntax in SpannerIO.java is tested to be correct? |
||
| when(resultSet.next()).thenReturn(true).thenReturn(false); | ||
| when(resultSet.getString(0)).thenReturn("MUTABLE_KEY_RANGE"); | ||
|
|
||
| assertEquals( | ||
| true, | ||
| SpannerIO.isMutableChangeStream( | ||
| databaseClient, Dialect.GOOGLE_STANDARD_SQL, TEST_CHANGE_STREAM)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFetchPartitionModePostgres() { | ||
| DatabaseClient databaseClient = Mockito.mock(DatabaseClient.class); | ||
| ReadOnlyTransaction transaction = Mockito.mock(ReadOnlyTransaction.class); | ||
| ResultSet resultSet = Mockito.mock(ResultSet.class); | ||
|
|
||
| when(databaseClient.readOnlyTransaction()).thenReturn(transaction); | ||
| when(transaction.executeQuery(any(Statement.class))).thenReturn(resultSet); | ||
| when(resultSet.next()).thenReturn(true).thenReturn(false); | ||
| when(resultSet.getString(0)).thenReturn("IMMUTABLE_KEY_RANGE"); | ||
|
|
||
| assertEquals( | ||
| false, | ||
| SpannerIO.isMutableChangeStream(databaseClient, Dialect.POSTGRESQL, TEST_CHANGE_STREAM)); | ||
| } | ||
|
|
||
| @Test | ||
| public void testFetchPartitionModeNotFound() { | ||
| DatabaseClient databaseClient = Mockito.mock(DatabaseClient.class); | ||
| ReadOnlyTransaction transaction = Mockito.mock(ReadOnlyTransaction.class); | ||
| ResultSet resultSet = Mockito.mock(ResultSet.class); | ||
|
|
||
| when(databaseClient.readOnlyTransaction()).thenReturn(transaction); | ||
| when(transaction.executeQuery(any(Statement.class))).thenReturn(resultSet); | ||
| when(resultSet.next()).thenReturn(false); | ||
|
|
||
| assertEquals( | ||
| false, | ||
| SpannerIO.isMutableChangeStream( | ||
| databaseClient, Dialect.GOOGLE_STANDARD_SQL, TEST_CHANGE_STREAM)); | ||
| } | ||
| } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also should the the failure or throw exception case of fetch option sql statement be tested as well? |
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following 2 lines of comments can be combined.