-
Notifications
You must be signed in to change notification settings - Fork 18
Add IT that ALTERs right before Reader fetches next page #134
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4884c27
Shade test jars
Bouncheck 468939d
Allow setting default query fetch size
Bouncheck 8c81cf4
Create test-jar of scylla-cdc-driver3 module
Bouncheck d4f5d88
Add driver3 test-jar dependency to scylla-cdc-lib
Bouncheck ad09197
Rework alter table tests in scylla-cdc-lib
Bouncheck 2ba2cfe
Rename method in AlterTableBase
Bouncheck ac6eb12
Add exception handling to datagen task in AlterDropColIT
Bouncheck 9f84589
Set method as table name in all AlterTableBase tests
Bouncheck File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
scylla-cdc-driver3/src/test/java/com/scylladb/cdc/cql/driver3/MockDriver3WorkerCQL.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| package com.scylladb.cdc.cql.driver3; | ||
|
|
||
| import com.datastax.driver.core.ResultSet; | ||
| import com.datastax.driver.core.ResultSetFuture; | ||
| import com.google.common.util.concurrent.FutureCallback; | ||
| import com.google.common.util.concurrent.Futures; | ||
| import com.google.common.util.concurrent.MoreExecutors; | ||
| import com.scylladb.cdc.model.worker.ChangeId; | ||
| import com.scylladb.cdc.model.worker.RawChange; | ||
| import com.scylladb.cdc.model.worker.Task; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.concurrent.CompletableFuture; | ||
| import java.util.concurrent.locks.ReadWriteLock; | ||
| import java.util.concurrent.locks.ReentrantReadWriteLock; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| // Created for alterTableBeforeNextPage test method | ||
| public class MockDriver3WorkerCQL extends Driver3WorkerCQL { | ||
| public final ReentrantReadWriteLock nextPageLock; | ||
| public final ReentrantReadWriteLock nextRowLock; | ||
|
|
||
| public MockDriver3WorkerCQL(Driver3Session driver3Session) { | ||
| this(driver3Session, new ReentrantReadWriteLock(), new ReentrantReadWriteLock()); | ||
| } | ||
|
|
||
| public MockDriver3WorkerCQL(Driver3Session driver3Session, ReentrantReadWriteLock nextPageLock, ReentrantReadWriteLock nextRowLock) { | ||
| super(driver3Session); | ||
| this.nextPageLock = nextPageLock; | ||
| this.nextRowLock = nextRowLock; | ||
| } | ||
|
|
||
| public class MockDriver3Reader extends Driver3WorkerCQL.Driver3Reader { | ||
| // Write lock will be used for blocking from outside. | ||
| // Read lock will be used inside the worker. | ||
| public final ReadWriteLock nextPageLock; | ||
| public final ReadWriteLock nextRowLock; | ||
|
|
||
| public MockDriver3Reader(ResultSet rs, Optional<ChangeId> lastChangeId, ReadWriteLock nextPageLock, ReadWriteLock nextRowLock) { | ||
| super(rs, lastChangeId); | ||
| this.nextPageLock = nextPageLock; | ||
| this.nextRowLock = nextRowLock; | ||
| } | ||
|
|
||
| @Override | ||
| protected void findNext(CompletableFuture<Optional<RawChange>> fut) { | ||
| if (rs.getAvailableWithoutFetching() == 0 && !rs.isFullyFetched()) { | ||
| nextPageLock.readLock().lock(); | ||
| try { | ||
| super.findNext(fut); | ||
| } finally { | ||
| nextPageLock.readLock().unlock(); | ||
| } | ||
| } else { | ||
| nextRowLock.readLock().lock(); | ||
| try { | ||
| super.findNext(fut); | ||
| } finally { | ||
| nextRowLock.readLock().unlock(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public class MockDriver3MultiReader extends Driver3WorkerCQL.Driver3MultiReader { | ||
| public MockDriver3MultiReader(List<ResultSet> rss, Optional<ChangeId> lastChangeId) { | ||
| super(rss, lastChangeId); | ||
| this.readers = rss.stream().map(rs -> new MockDriver3Reader(rs, lastChangeId, nextPageLock, nextRowLock)).collect(Collectors.toList()); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| protected CompletableFuture<Reader> wrapResults(Task task, List<ResultSetFuture> futures) { | ||
| CompletableFuture<Reader> result = new CompletableFuture<>(); | ||
| Futures.addCallback(Futures.allAsList(futures), new FutureCallback<List<ResultSet>>() { | ||
| @Override | ||
| public void onSuccess(List<ResultSet> rss) { | ||
| result.complete(new MockDriver3MultiReader(rss, task.state.getLastConsumedChangeId())); | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(Throwable t) { | ||
| result.completeExceptionally(t); | ||
| } | ||
| }, MoreExecutors.directExecutor()); | ||
| return result; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
scylla-cdc-lib/src/test/java/com/scylladb/cdc/lib/AlterAddColIT.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| package com.scylladb.cdc.lib; | ||
|
|
||
| import com.datastax.driver.core.PreparedStatement; | ||
| import com.google.common.util.concurrent.Uninterruptibles; | ||
| import com.scylladb.cdc.model.worker.RawChange; | ||
| import org.junit.jupiter.api.Tag; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.TestInfo; | ||
| import org.opentest4j.AssertionFailedError; | ||
|
|
||
| import java.util.concurrent.TimeUnit; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
|
||
| @Tag("integration") | ||
| public class AlterAddColIT extends AlterTableBase { | ||
| @Override | ||
| public String testKeyspace() { | ||
| return "AlterAddColIT".toLowerCase(); | ||
| } | ||
|
|
||
| @Override | ||
| public String createTableQuery() { | ||
| return String.format( | ||
| "CREATE TABLE %s.%s (column1 int, column2 int, column3 int, PRIMARY" | ||
| + " KEY (column1, column2)) WITH cdc = {'enabled': 'true'};", | ||
| testKeyspace(), testTable()); | ||
| } | ||
|
|
||
| @Override | ||
| public void applyAlteration() { | ||
| getDriverSession().execute(String.format("ALTER TABLE %s.%s " + "ADD column4 int;", testKeyspace(), testTable())); | ||
| } | ||
|
|
||
|
|
||
| @Override | ||
| public void verifyRawChangeBeforeAlter(RawChange change) { | ||
| assertEquals("cdc$stream_id", change.getSchema().getColumnDefinition(0).getColumnName()); | ||
| assertEquals("cdc$time", change.getSchema().getColumnDefinition(1).getColumnName()); | ||
| assertEquals("cdc$batch_seq_no", change.getSchema().getColumnDefinition(2).getColumnName()); | ||
| assertEquals( | ||
| "cdc$deleted_column3", change.getSchema().getColumnDefinition(3).getColumnName()); | ||
| assertEquals("cdc$end_of_batch", change.getSchema().getColumnDefinition(4).getColumnName()); | ||
| assertEquals("cdc$operation", change.getSchema().getColumnDefinition(5).getColumnName()); | ||
| assertEquals("cdc$ttl", change.getSchema().getColumnDefinition(6).getColumnName()); | ||
| assertEquals("column1", change.getSchema().getColumnDefinition(7).getColumnName()); | ||
| assertEquals("column2", change.getSchema().getColumnDefinition(8).getColumnName()); | ||
| assertEquals("column3", change.getSchema().getColumnDefinition(9).getColumnName()); | ||
| } | ||
|
|
||
| @Override | ||
| public void verifyRawChangeAfterAlter(RawChange change) { | ||
| assertEquals("cdc$stream_id", change.getSchema().getColumnDefinition(0).getColumnName()); | ||
| assertEquals("cdc$time", change.getSchema().getColumnDefinition(1).getColumnName()); | ||
| assertEquals("cdc$batch_seq_no", change.getSchema().getColumnDefinition(2).getColumnName()); | ||
| assertEquals( | ||
| "cdc$deleted_column3", change.getSchema().getColumnDefinition(3).getColumnName()); | ||
| assertEquals( | ||
| "cdc$deleted_column4", change.getSchema().getColumnDefinition(4).getColumnName()); | ||
| assertEquals("cdc$end_of_batch", change.getSchema().getColumnDefinition(5).getColumnName()); | ||
| assertEquals("cdc$operation", change.getSchema().getColumnDefinition(6).getColumnName()); | ||
| assertEquals("cdc$ttl", change.getSchema().getColumnDefinition(7).getColumnName()); | ||
| assertEquals("column1", change.getSchema().getColumnDefinition(8).getColumnName()); | ||
| assertEquals("column2", change.getSchema().getColumnDefinition(9).getColumnName()); | ||
| assertEquals("column3", change.getSchema().getColumnDefinition(10).getColumnName()); | ||
| assertEquals("column4", change.getSchema().getColumnDefinition(11).getColumnName()); | ||
| } | ||
|
|
||
| @Override | ||
| public Runnable createDatagenTask() { | ||
| return () -> { | ||
| PreparedStatement ps = | ||
| getDriverSession().prepare( | ||
| String.format( | ||
| "INSERT INTO %s.%s (column1, column2, column3) VALUES (?, ?, ?);", | ||
| testKeyspace(), testTable())); | ||
| while (!datagenShouldStop.get()) { | ||
| int current = datagenCounter.incrementAndGet(); | ||
| getDriverSession().execute(ps.bind(1, 1, current)); | ||
| Uninterruptibles.sleepUninterruptibly(100, TimeUnit.MILLISECONDS); | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| @Test | ||
| public void alterBeforeNextPageTest(TestInfo testInfo) { | ||
| setTestTableName(testInfo.getTestMethod().get().getName().toLowerCase()); | ||
| super.alterBeforeNextPageTestBody(); | ||
| } | ||
|
|
||
| @Test | ||
| public void alterBeforeNextRowTest(TestInfo testInfo) { | ||
| setTestTableName(testInfo.getTestMethod().get().getName().toLowerCase()); | ||
| try { | ||
| super.alterBeforeNextRowTestBody(); | ||
| } catch (AssertionFailedError e) { | ||
| // Ignoring. It is bound to appear, because the alter cannot modify already fetched rows. | ||
| // CDCConsumer has no knowledge about from which page the RawChange comes. | ||
| // This test only checks that the setup does not break on anything else. | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.