protected void assertRegexList(String patterns, String... matches) { List<Pattern> regexList = Strings.listOfRegex(patterns, Pattern.CASE_INSENSITIVE); assertThat(regexList.stream() .map(Pattern::pattern) .collect(Collectors.toList())).isEqualTo(Arrays.asList((Object[])matches)); } }
@Test public void shouldFilterAndMergeGtidSet() throws Exception { String gtidStr = "036d85a9-64e5-11e6-9b48-42010af0000c:1-2," + "7c1de3f2-3fd2-11e6-9cdc-42010af000bc:5-41"; String availableServerGtidStr = "036d85a9-64e5-11e6-9b48-42010af0000c:1-20," + "7145bf69-d1ca-11e5-a588-0242ac110004:1-3200," + "123e4567-e89b-12d3-a456-426655440000:1-41"; String purgedServerGtidStr = ""; config = simpleConfig().with(MySqlConnectorConfig.GTID_SOURCE_INCLUDES, "036d85a9-64e5-11e6-9b48-42010af0000c") .build(); context = new MySqlTaskContext(config, new Filters.Builder(config).build(), false, null); context.start(); context.source().setCompletedGtidSet(gtidStr); GtidSet mergedGtidSet = context.filterGtidSet(new GtidSet(availableServerGtidStr), new GtidSet(purgedServerGtidStr)); assertThat(mergedGtidSet).isNotNull(); GtidSet.UUIDSet uuidSet1 = mergedGtidSet.forServerWithId("036d85a9-64e5-11e6-9b48-42010af0000c"); GtidSet.UUIDSet uuidSet2 = mergedGtidSet.forServerWithId("7145bf69-d1ca-11e5-a588-0242ac110004"); GtidSet.UUIDSet uuidSet3 = mergedGtidSet.forServerWithId("123e4567-e89b-12d3-a456-426655440000"); GtidSet.UUIDSet uuidSet4 = mergedGtidSet.forServerWithId("7c1de3f2-3fd2-11e6-9cdc-42010af000bc"); assertThat(uuidSet1.getIntervals()).isEqualTo(Arrays.asList(new GtidSet.Interval(1, 2))); assertThat(uuidSet2.getIntervals()).isEqualTo(Arrays.asList(new GtidSet.Interval(1, 3200))); assertThat(uuidSet3.getIntervals()).isEqualTo(Arrays.asList(new GtidSet.Interval(1, 41))); assertThat(uuidSet4).isNull(); }
@Test @FixFor("DBZ-923") public void shouldMergeToFirstAvailableGtidSetPositions() throws Exception { String gtidStr = "036d85a9-64e5-11e6-9b48-42010af0000c:1-2," + "7c1de3f2-3fd2-11e6-9cdc-42010af000bc:5-41"; String availableServerGtidStr = "036d85a9-64e5-11e6-9b48-42010af0000c:1-20," + "7145bf69-d1ca-11e5-a588-0242ac110004:1-3200," + "123e4567-e89b-12d3-a456-426655440000:1-41"; String purgedServerGtidStr = "7145bf69-d1ca-11e5-a588-0242ac110004:1-1234"; config = simpleConfig() .with(MySqlConnectorConfig.GTID_SOURCE_INCLUDES, "036d85a9-64e5-11e6-9b48-42010af0000c") .with(MySqlConnectorConfig.GTID_NEW_CHANNEL_POSITION, GtidNewChannelPosition.EARLIEST) .build(); context = new MySqlTaskContext(config, new Filters.Builder(config).build(), false, null); context.start(); context.source().setCompletedGtidSet(gtidStr); GtidSet mergedGtidSet = context.filterGtidSet(new GtidSet(availableServerGtidStr), new GtidSet(purgedServerGtidStr)); assertThat(mergedGtidSet).isNotNull(); GtidSet.UUIDSet uuidSet1 = mergedGtidSet.forServerWithId("036d85a9-64e5-11e6-9b48-42010af0000c"); GtidSet.UUIDSet uuidSet2 = mergedGtidSet.forServerWithId("7145bf69-d1ca-11e5-a588-0242ac110004"); GtidSet.UUIDSet uuidSet3 = mergedGtidSet.forServerWithId("123e4567-e89b-12d3-a456-426655440000"); GtidSet.UUIDSet uuidSet4 = mergedGtidSet.forServerWithId("7c1de3f2-3fd2-11e6-9cdc-42010af000bc"); assertThat(uuidSet1.getIntervals()).isEqualTo(Arrays.asList(new GtidSet.Interval(1, 2))); assertThat(uuidSet2.getIntervals()).isEqualTo(Arrays.asList(new GtidSet.Interval(1, 1234))); assertThat(uuidSet3).isNull(); assertThat(uuidSet4).isNull(); }
private void validateFieldDef(Field expected) { ConfigDef configDef = connector.config(); assertThat(configDef.names()).contains(expected.name()); ConfigDef.ConfigKey key = configDef.configKeys().get(expected.name()); assertThat(key).isNotNull(); assertThat(key.name).isEqualTo(expected.name()); assertThat(key.displayName).isEqualTo(expected.displayName()); assertThat(key.importance).isEqualTo(expected.importance()); assertThat(key.documentation).isEqualTo(expected.description()); assertThat(key.type).isEqualTo(expected.type()); assertThat(key.defaultValue).isEqualTo(expected.defaultValue()); assertThat(key.dependents).isEqualTo(expected.dependents()); assertThat(key.width).isNotNull(); assertThat(key.group).isNotNull(); assertThat(key.orderInGroup).isGreaterThan(0); assertThat(key.validator).isNull(); assertThat(key.recommender).isNull(); } }
protected static void assertConfigDefIsValid(Connector connector, io.debezium.config.Field.Set fields) { ConfigDef configDef = connector.config(); assertThat(configDef).isNotNull(); fields.forEach(expected -> { assertThat(configDef.names()).contains(expected.name()); ConfigKey key = configDef.configKeys().get(expected.name()); assertThat(key).isNotNull(); assertThat(key.name).isEqualTo(expected.name()); assertThat(key.displayName).isEqualTo(expected.displayName()); assertThat(key.importance).isEqualTo(expected.importance()); assertThat(key.documentation).isEqualTo(expected.description()); assertThat(key.type).isEqualTo(expected.type()); if (expected.equals(MySqlConnectorConfig.DATABASE_HISTORY) || expected.equals(MySqlConnectorConfig.JDBC_DRIVER)) { assertThat(((Class<?>) key.defaultValue).getName()).isEqualTo((String) expected.defaultValue()); } else if (!expected.equals(MySqlConnectorConfig.SERVER_ID)) { assertThat(key.defaultValue).isEqualTo(expected.defaultValue()); } assertThat(key.dependents).isEqualTo(expected.dependents()); assertThat(key.width).isNotNull(); assertThat(key.group).isNotNull(); assertThat(key.orderInGroup).isGreaterThan(0); assertThat(key.validator).isNull(); assertThat(key.recommender).isNull(); }); } }
protected static void assertConfigDefIsValid(Connector connector, io.debezium.config.Field.Set fields) { ConfigDef configDef = connector.config(); assertThat(configDef).isNotNull(); fields.forEach(expected -> { assertThat(configDef.names()).contains(expected.name()); ConfigKey key = configDef.configKeys().get(expected.name()); assertThat(key).isNotNull(); assertThat(key.name).isEqualTo(expected.name()); assertThat(key.displayName).isEqualTo(expected.displayName()); assertThat(key.importance).isEqualTo(expected.importance()); assertThat(key.documentation).isEqualTo(expected.description()); assertThat(key.type).isEqualTo(expected.type()); assertThat(key.defaultValue).isEqualTo(expected.defaultValue()); assertThat(key.dependents).isEqualTo(expected.dependents()); assertThat(key.width).isNotNull(); assertThat(key.group).isNotNull(); assertThat(key.orderInGroup).isGreaterThan(0); assertThat(key.validator).isNull(); assertThat(key.recommender).isNull(); }); }
private void assertModelsInBackend() { final List<T> instances = createInBackendByName(modelNames()); final List<String> actualNames = instances.stream().map(o -> extractName(o)). filter(name -> modelNames().contains(name)).sorted().collect(toList()); assertThat(actualNames). overridingErrorMessage(String.format("The test requires instances with the names %s.", Iterables.toString(modelNames()))). isEqualTo(modelNames()); }
private void assertModelsInBackend() { final List<T> instances = createInBackendByName(modelNames()); final List<String> actualNames = instances.stream().map(o -> extractName(o)). filter(name -> modelNames().contains(name)).sorted().collect(toList()); assertThat(actualNames). overridingErrorMessage(String.format("The test requires instances with the names %s.", IterableUtils.toString(modelNames()))). isEqualTo(modelNames()); }
public void assertManifestContainsSourcesEntry(IDirectory dir, String expectedSources) { HashSet<String> found = new HashSet<String>(); DynamicArray<? extends IFile> files = IDirectoryUtil.allContainedFilesExcludingIgnored(dir); for (IFile file : files) { String extension = file.getExtension(); if (extension.equals("gs") || extension.equals("gsx") || extension.equals("xsd")) { found.add(extension); } } List<String> foundExtensions = new ArrayList<String>(found); Collections.sort(foundExtensions); if (expectedSources != null) { List<String> expectedSourceExtensions = Arrays.asList(expectedSources.split(",")); Assertions.assertThat(foundExtensions) .as("the set of extensions in the manifest (Contains-Sources) don't match the set found in the jar") .isEqualTo(expectedSourceExtensions); assertEquals(expectedSources, _mf.getMainAttributes().getValue("Contains-Sources")); } else { Assertions.assertThat(foundExtensions).isEmpty(); assertNull(_mf.getMainAttributes().getValue("Contains-Sources")); } }
@Test public void queryAllScenario() { assertModelsNotPresent(); assertModelsInBackend(); final PagedQueryResult<T> queryResult = queryAll(); assertThat(getNames(queryResult.getResults()).stream(). filter(name -> modelNames().contains(name)).sorted().collect(toList())).isEqualTo(modelNames()); cleanUpByName(modelNames()); }
@Test public void testResultListWithoutProjection() { inTransaction( session -> { List<Movie> movies = session.createQuery( JPQL_QUERY_WITHOUT_PROJECTION ) .getResultList(); assertThat( movies ).isEqualTo( Collections.singletonList( originalMovie ) ); } ); }
/** * This methods behave like {@link ListAssert#containsExactly(Object...)} with the exception that the order of the * null elements is ignored if {@link OrderedListAssert#ignoreNullOrder()} is called. * Note that in this last case, the test will fail if nulls are both at the end and at the beginning. * * @see ListAssert#containsExactly(Object...) */ @Override public OrderedListAssert containsExactly(Object... expected) { if ( ignoringNullPosition ) { Assertions.assertThat( actual ).hasSize( expected.length ); List<Object> actualWithoutNull = trimNull( actual ); List<Object> expectedWithoutNull = trimNull( Arrays.asList( expected ) ); Assertions.assertThat( actualWithoutNull ).isEqualTo( expectedWithoutNull ); if ( actual.size() > 1 && actualWithoutNull.size() > 0 ) { if ( actual.get( 0 ) == null && actual.get( actual.size() - 1 ) == null ) { throw failure( "Null order should be consistent: " + actual ); } } } else { super.containsExactly( expected ); } return this; }
@Test public void shouldFilterAndMergeGtidSet() throws Exception { String gtidStr = "036d85a9-64e5-11e6-9b48-42010af0000c:1-2," + "7c1de3f2-3fd2-11e6-9cdc-42010af000bc:5-41"; String availableServerGtidStr = "036d85a9-64e5-11e6-9b48-42010af0000c:1-20," + "7145bf69-d1ca-11e5-a588-0242ac110004:1-3200," + "123e4567-e89b-12d3-a456-426655440000:1-41"; String purgedServerGtidStr = ""; config = simpleConfig().with(MySqlConnectorConfig.GTID_SOURCE_INCLUDES, "036d85a9-64e5-11e6-9b48-42010af0000c") .build(); context = new MySqlTaskContext(config, new Filters.Builder(config).build(), false, null); context.start(); context.source().setCompletedGtidSet(gtidStr); GtidSet mergedGtidSet = context.filterGtidSet(new GtidSet(availableServerGtidStr), new GtidSet(purgedServerGtidStr)); assertThat(mergedGtidSet).isNotNull(); GtidSet.UUIDSet uuidSet1 = mergedGtidSet.forServerWithId("036d85a9-64e5-11e6-9b48-42010af0000c"); GtidSet.UUIDSet uuidSet2 = mergedGtidSet.forServerWithId("7145bf69-d1ca-11e5-a588-0242ac110004"); GtidSet.UUIDSet uuidSet3 = mergedGtidSet.forServerWithId("123e4567-e89b-12d3-a456-426655440000"); GtidSet.UUIDSet uuidSet4 = mergedGtidSet.forServerWithId("7c1de3f2-3fd2-11e6-9cdc-42010af000bc"); assertThat(uuidSet1.getIntervals()).isEqualTo(Arrays.asList(new GtidSet.Interval(1, 2))); assertThat(uuidSet2.getIntervals()).isEqualTo(Arrays.asList(new GtidSet.Interval(1, 3200))); assertThat(uuidSet3.getIntervals()).isEqualTo(Arrays.asList(new GtidSet.Interval(1, 41))); assertThat(uuidSet4).isNull(); }
@Test @FixFor("DBZ-923") public void shouldMergeToFirstAvailableGtidSetPositions() throws Exception { String gtidStr = "036d85a9-64e5-11e6-9b48-42010af0000c:1-2," + "7c1de3f2-3fd2-11e6-9cdc-42010af000bc:5-41"; String availableServerGtidStr = "036d85a9-64e5-11e6-9b48-42010af0000c:1-20," + "7145bf69-d1ca-11e5-a588-0242ac110004:1-3200," + "123e4567-e89b-12d3-a456-426655440000:1-41"; String purgedServerGtidStr = "7145bf69-d1ca-11e5-a588-0242ac110004:1-1234"; config = simpleConfig() .with(MySqlConnectorConfig.GTID_SOURCE_INCLUDES, "036d85a9-64e5-11e6-9b48-42010af0000c") .with(MySqlConnectorConfig.GTID_NEW_CHANNEL_POSITION, GtidNewChannelPosition.EARLIEST) .build(); context = new MySqlTaskContext(config, new Filters.Builder(config).build(), false, null); context.start(); context.source().setCompletedGtidSet(gtidStr); GtidSet mergedGtidSet = context.filterGtidSet(new GtidSet(availableServerGtidStr), new GtidSet(purgedServerGtidStr)); assertThat(mergedGtidSet).isNotNull(); GtidSet.UUIDSet uuidSet1 = mergedGtidSet.forServerWithId("036d85a9-64e5-11e6-9b48-42010af0000c"); GtidSet.UUIDSet uuidSet2 = mergedGtidSet.forServerWithId("7145bf69-d1ca-11e5-a588-0242ac110004"); GtidSet.UUIDSet uuidSet3 = mergedGtidSet.forServerWithId("123e4567-e89b-12d3-a456-426655440000"); GtidSet.UUIDSet uuidSet4 = mergedGtidSet.forServerWithId("7c1de3f2-3fd2-11e6-9cdc-42010af000bc"); assertThat(uuidSet1.getIntervals()).isEqualTo(Arrays.asList(new GtidSet.Interval(1, 2))); assertThat(uuidSet2.getIntervals()).isEqualTo(Arrays.asList(new GtidSet.Interval(1, 1234))); assertThat(uuidSet3).isNull(); assertThat(uuidSet4).isNull(); }
private static void verifyIssue(TestIssue expected, Issue actual, File file) { if (line(actual) > expected.line()) { fail("Missing issue at line " + expected.line() + " in file " + file.getAbsolutePath()); } if (line(actual) < expected.line()) { fail("Unexpected issue at line " + line(actual) + ": \"" + message(actual) + "\"" + " in file " + file.getAbsolutePath()); } if (expected.message() != null) { assertThat(message(actual)).as("Bad message at line " + expected.line()).isEqualTo(expected.message()); } if (expected.effortToFix() != null) { assertThat(actual.cost()).as("Bad effortToFix at line " + expected.line()).isEqualTo(expected.effortToFix()); } if (expected.startColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().startLineOffset() + 1).as("Bad start column at line " + expected.line()).isEqualTo(expected.startColumn()); } if (expected.endColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLineOffset() + 1).as("Bad end column at line " + expected.line()).isEqualTo(expected.endColumn()); } if (expected.endLine() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLine()).as("Bad end line at line " + expected.line()).isEqualTo(expected.endLine()); } if (expected.secondaryLines() != null) { assertThat(secondary(actual)).as("Bad secondary locations at line " + expected.line()).isEqualTo(expected.secondaryLines()); } }
private static void verifyIssue(TestIssue expected, Issue actual, File file) { if (line(actual) > expected.line()) { fail("Missing issue at line " + expected.line() + " in file " + file.getAbsolutePath()); } if (line(actual) < expected.line()) { fail("Unexpected issue at line " + line(actual) + ": \"" + message(actual) + "\"" + " in file " + file.getAbsolutePath()); } if (expected.message() != null) { assertThat(message(actual)).as("Bad message at line " + expected.line()).isEqualTo(expected.message()); } if (expected.effortToFix() != null) { assertThat(actual.cost()).as("Bad effortToFix at line " + expected.line()).isEqualTo(expected.effortToFix()); } if (expected.startColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().startLineOffset() + 1).as("Bad start column at line " + expected.line()).isEqualTo(expected.startColumn()); } if (expected.endColumn() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLineOffset() + 1).as("Bad end column at line " + expected.line()).isEqualTo(expected.endColumn()); } if (expected.endLine() != null) { assertThat(((PreciseIssue) actual).primaryLocation().endLine()).as("Bad end line at line " + expected.line()).isEqualTo(expected.endLine()); } if (expected.secondaryLines() != null) { assertThat(secondary(actual)).as("Bad secondary locations at line " + expected.line()).isEqualTo(expected.secondaryLines()); } }
private void validateFieldDef(Field expected) { ConfigDef configDef = connector.config(); assertThat(configDef.names()).contains(expected.name()); ConfigDef.ConfigKey key = configDef.configKeys().get(expected.name()); assertThat(key).isNotNull(); assertThat(key.name).isEqualTo(expected.name()); assertThat(key.displayName).isEqualTo(expected.displayName()); assertThat(key.importance).isEqualTo(expected.importance()); assertThat(key.documentation).isEqualTo(expected.description()); assertThat(key.type).isEqualTo(expected.type()); assertThat(key.defaultValue).isEqualTo(expected.defaultValue()); assertThat(key.dependents).isEqualTo(expected.dependents()); assertThat(key.width).isNotNull(); assertThat(key.group).isNotNull(); assertThat(key.orderInGroup).isGreaterThan(0); assertThat(key.validator).isNull(); assertThat(key.recommender).isNull(); } }
protected static void assertConfigDefIsValid(Connector connector, io.debezium.config.Field.Set fields) { ConfigDef configDef = connector.config(); assertThat(configDef).isNotNull(); fields.forEach(expected -> { assertThat(configDef.names()).contains(expected.name()); ConfigKey key = configDef.configKeys().get(expected.name()); assertThat(key).isNotNull(); assertThat(key.name).isEqualTo(expected.name()); assertThat(key.displayName).isEqualTo(expected.displayName()); assertThat(key.importance).isEqualTo(expected.importance()); assertThat(key.documentation).isEqualTo(expected.description()); assertThat(key.type).isEqualTo(expected.type()); if (expected.equals(MySqlConnectorConfig.DATABASE_HISTORY) || expected.equals(MySqlConnectorConfig.JDBC_DRIVER)) { assertThat(((Class<?>) key.defaultValue).getName()).isEqualTo((String) expected.defaultValue()); } else if (!expected.equals(MySqlConnectorConfig.SERVER_ID)) { assertThat(key.defaultValue).isEqualTo(expected.defaultValue()); } assertThat(key.dependents).isEqualTo(expected.dependents()); assertThat(key.width).isNotNull(); assertThat(key.group).isNotNull(); assertThat(key.orderInGroup).isGreaterThan(0); assertThat(key.validator).isNull(); assertThat(key.recommender).isNull(); }); } }