org.hamcrest.collection.IsEmptyCollection Java Examples

The following examples show how to use org.hamcrest.collection.IsEmptyCollection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CubeOTTest.java    From datakernel with Apache License 2.0 6 votes vote down vote up
@Test
public void test() throws OTTransformException {
	LogFile logFile = new LogFile("file", 1);
	List<String> fields = asList("field1", "field2");
	LogDiff<CubeDiff> changesLeft = LogDiff.of(
			singletonMap("clicks", positionDiff(logFile, 0, 10)),
			cubeDiff("key", chunk(1, fields, ofArray("str", 10), ofArray("str", 20), 15)));

	LogDiff<CubeDiff> changesRight = LogDiff.of(
			singletonMap("clicks", positionDiff(logFile, 0, 20)),
			cubeDiff("key", chunk(1, fields, ofArray("str", 10), ofArray("str", 25), 30)));
	TransformResult<LogDiff<CubeDiff>> transform = logSystem.transform(changesLeft, changesRight);

	assertTrue(transform.hasConflict());
	assertEquals(ConflictResolution.RIGHT, transform.resolution);
	assertThat(transform.right, IsEmptyCollection.empty());

	LogDiff<CubeDiff> result = LogDiff.of(
			singletonMap("clicks", positionDiff(logFile, 10, 20)),
			cubeDiff("key", addedChunks(changesRight.getDiffs()), addedChunks(changesLeft.getDiffs())));

	assertEquals(1, transform.left.size());
	assertEquals(result, transform.left.get(0));
}
 
Example #2
Source File: TestAbstractMysqlSource.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnCorrectOffsetForFilteredOutEvents() throws Exception {
  MysqlBinLogSourceConfig config = createConfig("root");
  MysqlBinLogSource source = createMysqlSource(config);
  config.ignoreTables = "test.foo";
  runner = new SourceRunner.Builder(MySQLBinLogDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();

  final String lastSourceOffset = null;
  StageRunner.Output output = runner.runProduce(lastSourceOffset, MAX_BATCH_SIZE);
  assertThat(output.getRecords().get(LANE), is(IsEmptyCollection.<Record>empty()));

  execute(ds, "INSERT INTO foo (bar) VALUES (1)");

  output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  List<Record> records = output.getRecords().get(LANE);
  assertThat(records, is(empty()));
  assertThat(output.getNewOffset(), not(isEmptyString()));
}
 
Example #3
Source File: TestAbstractMysqlSource.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIgnoreEmptyFilters() throws Exception {
  MysqlBinLogSourceConfig config = createConfig("root");
  MysqlBinLogSource source = createMysqlSource(config);
  config.includeTables = "";
  config.ignoreTables = "";
  runner = new SourceRunner.Builder(MySQLBinLogDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();

  final String lastSourceOffset = null;
  StageRunner.Output output = runner.runProduce(lastSourceOffset, MAX_BATCH_SIZE);
  assertThat(output.getRecords().get(LANE), is(IsEmptyCollection.<Record>empty()));

  execute(ds, "INSERT INTO foo (bar) VALUES (1)");
  execute(ds, "INSERT INTO foo2 VALUES (1, 2, 3)");

  output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  List<Record> records = output.getRecords().get(LANE);
  assertThat(records, hasSize(2));
}
 
Example #4
Source File: TestAbstractMysqlSource.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIncludeAndIgnoreTables() throws Exception {
  MysqlBinLogSourceConfig config = createConfig("root");
  MysqlBinLogSource source = createMysqlSource(config);
  config.includeTables = "test.foo,t%.foo2";
  config.ignoreTables = "test.foo";
  runner = new SourceRunner.Builder(MySQLBinLogDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();

  final String lastSourceOffset = null;
  StageRunner.Output output = runner.runProduce(lastSourceOffset, MAX_BATCH_SIZE);
  assertThat(output.getRecords().get(LANE), is(IsEmptyCollection.<Record>empty()));

  execute(ds, "INSERT INTO foo (bar) VALUES (1)");
  execute(ds, "INSERT INTO foo2 VALUES (1, 2, 3)");

  output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  List<Record> records = output.getRecords().get(LANE);
  assertThat(records, hasSize(1));
  assertThat(records.get(0).get("/Table").getValueAsString(), is("foo2"));
  execute(ds, "TRUNCATE foo");
  execute(ds, "TRUNCATE foo2");
}
 
Example #5
Source File: AbstractMysqlSource.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldReturnCorrectOffsetForFilteredOutEvents() throws Exception {
  MysqlSourceConfig config = createConfig("root");
  MysqlSource source = createMysqlSource(config);
  config.ignoreTables = "test.foo";
  runner = new SourceRunner.Builder(MysqlDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();

  final String lastSourceOffset = null;
  StageRunner.Output output = runner.runProduce(lastSourceOffset, MAX_BATCH_SIZE);
  assertThat(output.getRecords().get(LANE), is(IsEmptyCollection.<Record>empty()));

  execute(ds, "INSERT INTO foo (bar) VALUES (1)");

  output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  List<Record> records = output.getRecords().get(LANE);
  assertThat(records, is(empty()));
  assertThat(output.getNewOffset(), not(isEmptyString()));
}
 
Example #6
Source File: AbstractMysqlSource.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIgnoreEmptyFilters() throws Exception {
  MysqlSourceConfig config = createConfig("root");
  MysqlSource source = createMysqlSource(config);
  config.includeTables = "";
  config.ignoreTables = "";
  runner = new SourceRunner.Builder(MysqlDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();

  final String lastSourceOffset = null;
  StageRunner.Output output = runner.runProduce(lastSourceOffset, MAX_BATCH_SIZE);
  assertThat(output.getRecords().get(LANE), is(IsEmptyCollection.<Record>empty()));

  execute(ds, "INSERT INTO foo (bar) VALUES (1)");
  execute(ds, "INSERT INTO foo2 VALUES (1, 2, 3)");

  output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  List<Record> records = output.getRecords().get(LANE);
  assertThat(records, hasSize(2));
}
 
Example #7
Source File: AbstractMysqlSource.java    From datacollector with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldIncludeAndIgnoreTables() throws Exception {
  MysqlSourceConfig config = createConfig("root");
  MysqlSource source = createMysqlSource(config);
  config.includeTables = "test.foo,t%.foo2";
  config.ignoreTables = "test.foo";
  runner = new SourceRunner.Builder(MysqlDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();

  final String lastSourceOffset = null;
  StageRunner.Output output = runner.runProduce(lastSourceOffset, MAX_BATCH_SIZE);
  assertThat(output.getRecords().get(LANE), is(IsEmptyCollection.<Record>empty()));

  execute(ds, "INSERT INTO foo (bar) VALUES (1)");
  execute(ds, "INSERT INTO foo2 VALUES (1, 2, 3)");

  output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  List<Record> records = output.getRecords().get(LANE);
  assertThat(records, hasSize(1));
  assertThat(records.get(0).get("/Table").getValueAsString(), is("foo2"));
  execute(ds, "TRUNCATE foo");
  execute(ds, "TRUNCATE foo2");
}
 
Example #8
Source File: HttpResponseTest.java    From logbook with MIT License 5 votes vote down vote up
@Test
public void testEmptyCodes() {
    HttpResponse response = mock(HttpResponse.class);
    when(response.getReasonPhrase()).thenCallRealMethod();
    
    Set<Integer> list = new HashSet<>(RESPONSE_CODES);
    for(int i = 0; i < 1000; i++) {
        when(response.getStatus()).thenReturn(i);
        if(response.getReasonPhrase() != null && !list.remove(Integer.valueOf(i))) {
            fail("Unexpected reason phrase for code " + i);
        }
    }
    assertThat(list, IsEmptyCollection.empty());
}
 
Example #9
Source File: CacheManagerManagementTest.java    From cache2k with Apache License 2.0 5 votes vote down vote up
/**
 * https://github.com/jsr107/jsr107tck/issues/87
 * changed in 1.1, CacheManager.getCacheNames()
 * @throws MalformedObjectNameException
 */
@After
public void tearDown() throws MalformedObjectNameException {
  //assertEquals(0, mBeanServer.queryNames(new ObjectName("java.cache:*"), null).size());
  if (!cacheManager.isClosed()) {
    for (String cacheName : cacheManager.getCacheNames()) {
      cacheManager.destroyCache(cacheName);
    }
  }
  cacheManager.close();
  //All registered object names should be removed during shutdown
  assertThat(mBeanServer.queryNames(new ObjectName("javax.cache:*"), null), IsEmptyCollection.<ObjectName>empty());
}
 
Example #10
Source File: PayloadDeserializerTest.java    From java-jwt with MIT License 5 votes vote down vote up
@Test
public void shouldGetEmptyStringArrayWhenParsingEmptyTextNode() throws Exception {
    Map<String, JsonNode> tree = new HashMap<>();
    TextNode textNode = new TextNode("");
    tree.put("key", textNode);

    List<String> values = deserializer.getStringOrArray(tree, "key");
    assertThat(values, is(notNullValue()));
    assertThat(values, is(IsEmptyCollection.empty()));
}
 
Example #11
Source File: TestAbstractMysqlSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSendAllEventRecordsDiscardingbatchSize() throws Exception {
  int count = 100;
  for (int i = 0; i < count; i++) {
    execute(ds, String.format("INSERT INTO foo (bar) VALUES (%d)", i));
  }

  MysqlBinLogSourceConfig config = createConfig("root");
  MysqlBinLogSource source = createMysqlSource(config);
  runner = new SourceRunner.Builder(MySQLBinLogDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();

  final String lastSourceOffset = null;
  StageRunner.Output output = runner.runProduce(lastSourceOffset, count);
  assertThat(output.getRecords().get(LANE), is(IsEmptyCollection.<Record>empty()));

  execute(ds, "DELETE FROM foo");

  output = runner.runProduce(output.getNewOffset(), count / 2);

  List<Record> records = new ArrayList<>();
  records.addAll(output.getRecords().get(LANE));

  assertThat(records, hasSize(count));
}
 
Example #12
Source File: TestAbstractMysqlSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldStartFromCurrent() throws Exception {
  execute(ds, "INSERT INTO foo (bar) VALUES (1)");

  MysqlBinLogSourceConfig config = createConfig("root");
  config.startFromBeginning = false;
  MysqlBinLogSource source = createMysqlSource(config);
  runner = new SourceRunner.Builder(MySQLBinLogDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();

  final String lastSourceOffset = null;
  StageRunner.Output output = runner.runProduce(lastSourceOffset, MAX_BATCH_SIZE);
  List<Record> records = new ArrayList<>();

  while (!output.getRecords().get(LANE).isEmpty()) {
    records.addAll(output.getRecords().get(LANE));
    output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  }
  assertThat(records, is(IsEmptyCollection.<Record>empty()));

  // add one more
  execute(ds, "INSERT INTO foo (bar) VALUES (2)");
  output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  records.addAll(output.getRecords().get(LANE));

  Record found = null;
  for (Record record : records) {
    if (record.get("/Table").getValueAsString().equals("foo")) {
      found = record;
      break;
    }
  }
  assertThat(found, notNullValue());
  assertThat(found.get("/Data/bar"), is(create(2)));
}
 
Example #13
Source File: AbstractMysqlSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldSendAllEventRecordsDiscardingbatchSize() throws Exception {
  int count = 100;
  for (int i = 0; i < count; i++) {
    execute(ds, String.format("INSERT INTO foo (bar) VALUES (%d)", i));
  }

  MysqlSourceConfig config = createConfig("root");
  MysqlSource source = createMysqlSource(config);
  runner = new SourceRunner.Builder(MysqlDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();

  final String lastSourceOffset = null;
  StageRunner.Output output = runner.runProduce(lastSourceOffset, count);
  assertThat(output.getRecords().get(LANE), is(IsEmptyCollection.<Record>empty()));

  execute(ds, "DELETE FROM foo");

  output = runner.runProduce(output.getNewOffset(), count / 2);

  List<Record> records = new ArrayList<>();
  records.addAll(output.getRecords().get(LANE));

  assertThat(records, hasSize(count));
}
 
Example #14
Source File: AbstractMysqlSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldStartFromCurrent() throws Exception {
  execute(ds, "INSERT INTO foo (bar) VALUES (1)");

  MysqlSourceConfig config = createConfig("root");
  config.startFromBeginning = false;
  MysqlSource source = createMysqlSource(config);
  runner = new SourceRunner.Builder(MysqlDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();

  final String lastSourceOffset = null;
  StageRunner.Output output = runner.runProduce(lastSourceOffset, MAX_BATCH_SIZE);
  List<Record> records = new ArrayList<>();

  while (!output.getRecords().get(LANE).isEmpty()) {
    records.addAll(output.getRecords().get(LANE));
    output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  }
  assertThat(records, is(IsEmptyCollection.<Record>empty()));

  // add one more
  execute(ds, "INSERT INTO foo (bar) VALUES (2)");
  output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  records.addAll(output.getRecords().get(LANE));

  Record found = null;
  for (Record record : records) {
    if (record.get("/Table").getValueAsString().equals("foo")) {
      found = record;
      break;
    }
  }
  assertThat(found, notNullValue());
  assertThat(found.get("/Data/bar"), is(create(2)));
}
 
Example #15
Source File: PeersIT.java    From emissary with Apache License 2.0 5 votes vote down vote up
@Test
public void peers() {
    // test
    Response response = target("peers").request().get();

    // verify
    assertThat(response.getStatus(), equalTo(200));
    PeersResponseEntity entity = response.readEntity(PeersResponseEntity.class);
    assertThat(entity.getErrors(), IsEmptyCollection.empty());
    assertThat(entity.getCluster(), equalTo(null));
    assertThat(entity.getLocal().getHost(), equalTo(TestEmissaryNode.TEST_NODE_PORT));
    assertThat(entity.getLocal().getPeers(), equalTo(PEERS));

}
 
Example #16
Source File: I18nConfigOptionsProviderTest.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testRegion() throws Exception {
    assertThat(provider.getParameterOptions(uriI18N, "region", Locale.US), hasItem(expectedCntryEN));
    assertThat(provider.getParameterOptions(uriI18N, "region", Locale.FRENCH),
            anyOf(hasItem(expectedCntryFRJava8), hasItem(expectedCntryFRJava9)));
    assertThat(provider.getParameterOptions(uriI18N, "region", null), not(IsEmptyCollection.empty()));
}
 
Example #17
Source File: ReversedTest.java    From cactoos with MIT License 5 votes vote down vote up
@Test
public void reversesEmptyList() {
    new Assertion<>(
        "Must reverse empty list",
        new ListOf<>(
            new Reversed<>(
                new IteratorOf<>()
            )
        ),
        new IsEmptyCollection<>()
    ).affirm();
}
 
Example #18
Source File: AgentsTest.java    From emissary with Apache License 2.0 5 votes vote down vote up
@Ignore
// TODO: stop mocking and run a server since we made it so easy
@Test
public void agents() throws Exception {
    // test
    Response response = target("agents").request().get();

    // verify
    assertThat(response.getStatus(), equalTo(200));
    AgentsResponseEntity entity = response.readEntity(AgentsResponseEntity.class);
    assertThat(entity.getErrors(), IsEmptyCollection.empty());
    assertThat(entity.getCluster(), IsEmptyCollection.empty());
    assertThat(entity.getLocal().getHost(), equalTo("localhost:8001"));
    assertThat(entity.getLocal().getAgents(), IsIterableContainingInOrder.contains(EXPECTED_AGENTS));
}
 
Example #19
Source File: AuthenticationJsonWebTokenTest.java    From auth0-spring-security-api with MIT License 5 votes vote down vote up
@Test
public void shouldGetEmptyAuthoritiesOnMissingScopeClaim() throws Exception {
    String token = JWT.create()
            .sign(hmacAlgorithm);

    AuthenticationJsonWebToken auth = new AuthenticationJsonWebToken(token, verifier);
    assertThat(auth, is(notNullValue()));
    assertThat(auth.getAuthorities(), is(notNullValue()));
    assertThat(auth.getAuthorities(), is(IsEmptyCollection.empty()));
}
 
Example #20
Source File: AuthenticationJsonWebTokenTest.java    From auth0-spring-security-api with MIT License 5 votes vote down vote up
@Test
public void shouldGetEmptyAuthoritiesOnEmptyScopeClaim() throws Exception {
    String token = JWT.create()
            .withClaim("scope", "   ")
            .sign(hmacAlgorithm);

    AuthenticationJsonWebToken auth = new AuthenticationJsonWebToken(token, verifier);
    assertThat(auth, is(notNullValue()));
    assertThat(auth.getAuthorities(), is(notNullValue()));
    assertThat(auth.getAuthorities(), is(IsEmptyCollection.empty()));
}
 
Example #21
Source File: AuthenticationJsonWebTokenTest.java    From auth0-spring-security-api with MIT License 5 votes vote down vote up
@Test
public void shouldGetEmptyAuthoritiesOnEmptyPermissionsClaim() throws Exception {
    String token = JWT.create()
            .withArrayClaim("permissions", new String[]{})
            .sign(hmacAlgorithm);

    AuthenticationJsonWebToken auth = new AuthenticationJsonWebToken(token, verifier);
    assertThat(auth, is(notNullValue()));
    assertThat(auth.getAuthorities(), is(notNullValue()));
    assertThat(auth.getAuthorities(), is(IsEmptyCollection.empty()));
}
 
Example #22
Source File: PreAuthenticatedAuthenticationJsonWebTokenTest.java    From auth0-spring-security-api with MIT License 5 votes vote down vote up
@Test
public void shouldGetEmptyAuthoritiesOnMissingScopeClaim() throws Exception {
    String token = JWT.create()
            .sign(hmacAlgorithm);

    PreAuthenticatedAuthenticationJsonWebToken auth = usingToken(token);
    assertThat(auth, is(notNullValue()));
    assertThat(auth.getAuthorities(), is(notNullValue()));
    assertThat(auth.getAuthorities(), is(IsEmptyCollection.empty()));
}
 
Example #23
Source File: PreAuthenticatedAuthenticationJsonWebTokenTest.java    From auth0-spring-security-api with MIT License 5 votes vote down vote up
@Test
public void shouldAlwaysGetEmptyAuthorities() throws Exception {
    String token = JWT.create()
            .withClaim("scope", "read:users add:users")
            .sign(hmacAlgorithm);

    PreAuthenticatedAuthenticationJsonWebToken auth = usingToken(token);
    assertThat(auth, is(notNullValue()));
    assertThat(auth.getAuthorities(), is(notNullValue()));
    assertThat(auth.getAuthorities(), is(IsEmptyCollection.empty()));
}
 
Example #24
Source File: XmlGraphTest.java    From jpeek with MIT License 5 votes vote down vote up
@Test
void buildsConnections() {
    final Map<String, Node> byname = new MapOf<>(
        Node::name,
        node -> node,
        new XmlGraph(
            new Skeleton(new FakeBase(XmlGraphTest.CLASS_NAME))
        ).nodes()
    );
    final Node one = byname.get(XmlGraphTest.METHOD_ONE);
    final Node two = byname.get(XmlGraphTest.METHOD_TWO);
    final Node three = byname.get(XmlGraphTest.METHOD_THREE);
    final Node four = byname.get(XmlGraphTest.METHOD_FOUR);
    final Node five = byname.get(XmlGraphTest.METHOD_FIVE);
    new Assertion<>(
        "Must build nodes connections when called",
        one.connections(),
        new HasValues<>(two)
    ).affirm();
    new Assertion<>(
        "Must build nodes connections when called or calling",
        two.connections(),
        new HasValues<>(one, four)
    ).affirm();
    new Assertion<>(
        "Must build nodes connections when neither called nor calling",
        three.connections(),
        new IsEmptyCollection<>()
    ).affirm();
    new Assertion<>(
        "Must build nodes connections when calling",
        four.connections(),
        new HasValues<>(two)
    ).affirm();
    new Assertion<>(
        "Must build nodes connections when throwing",
        five.connections(),
        new IsEmptyCollection<>()
    ).affirm();
}
 
Example #25
Source File: ClaimImplTest.java    From JWTDecode.Android with MIT License 5 votes vote down vote up
@Test
public void shouldGetEmptyListIfNullValue() {
    JsonElement value = gson.toJsonTree(null);
    ClaimImpl claim = new ClaimImpl(value);

    assertThat(claim.asList(String.class), is(notNullValue()));
    assertThat(claim.asList(String.class), is(IsEmptyCollection.emptyCollectionOf(String.class)));
}
 
Example #26
Source File: ClaimImplTest.java    From JWTDecode.Android with MIT License 5 votes vote down vote up
@Test
public void shouldGetEmptyListIfNonArrayValue() {
    JsonElement value = gson.toJsonTree(1);
    ClaimImpl claim = new ClaimImpl(value);

    assertThat(claim.asList(String.class), is(notNullValue()));
    assertThat(claim.asList(String.class), is(IsEmptyCollection.emptyCollectionOf(String.class)));
}
 
Example #27
Source File: JWTTest.java    From JWTDecode.Android with MIT License 5 votes vote down vote up
@Test
public void shouldGetEmptyListAudienceIfMissing() {
    JWT jwt = new JWT("eyJhbGciOiJIUzI1NiJ9.e30.something");
    assertThat(jwt, is(notNullValue()));

    assertThat(jwt.getAudience(), IsEmptyCollection.<String>empty());
}
 
Example #28
Source File: SimpleAclOperatorIT.java    From strimzi-kafka-operator with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoAclRules(VertxTestContext context) {
    Set<SimpleAclRule> acls = simpleAclOperator.getAcls("no-acls-user");
    context.verify(() -> {
        assertThat(acls, IsEmptyCollection.empty());
    });
    context.completeNow();
}
 
Example #29
Source File: I18nConfigOptionsProviderTest.java    From openhab-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testLanguage() throws Exception {
    assertThat(provider.getParameterOptions(uriI18N, "language", Locale.US), hasItem(expectedLangEN));
    assertThat(provider.getParameterOptions(uriI18N, "language", Locale.FRENCH), hasItem(expectedLangFR));
    assertThat(provider.getParameterOptions(uriI18N, "language", null), not(IsEmptyCollection.empty()));
}
 
Example #30
Source File: TestAbstractMysqlSource.java    From datacollector with Apache License 2.0 4 votes vote down vote up
@Test
public void shouldCreateMutipleRecordsForEventWithMultipleRows() throws Exception {
  int count = 10;
  for (int i = 0; i < count; i++) {
    execute(ds, String.format("INSERT INTO foo (bar) VALUES (%d)", i));
  }

  MysqlBinLogSourceConfig config = createConfig("root");
  MysqlBinLogSource source = createMysqlSource(config);
  runner = new SourceRunner.Builder(MySQLBinLogDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();

  final String lastSourceOffset = null;
  StageRunner.Output output = runner.runProduce(lastSourceOffset, MAX_BATCH_SIZE);
  assertThat(output.getRecords().get(LANE), is(IsEmptyCollection.<Record>empty()));

  execute(ds, "DELETE FROM foo");

  output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);

  List<Record> records = new ArrayList<>();
  records.addAll(output.getRecords().get(LANE));

  assertThat(records, hasSize(count));
  for (int i = 0; i < count; i++) {
    Record rec = records.get(i);
    assertThat(rec.get("/Type"), is(create("DELETE")));
    assertThat(rec.get("/OldData/bar"), is(create(i)));
  }

  // no more data
  output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  assertThat(output.getRecords().get(LANE), is(IsEmptyCollection.<Record>empty()));

  // no more data after reconnect
  runner.runDestroy();
  runner = new SourceRunner.Builder(MySQLBinLogDSource.class, source)
      .addOutputLane(LANE)
      .build();
  runner.runInit();
  output = runner.runProduce(output.getNewOffset(), MAX_BATCH_SIZE);
  assertThat(output.getRecords().get(LANE), is(IsEmptyCollection.<Record>empty()));
}