org.apache.kafka.connect.data.Struct.getBoolean()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中org.apache.kafka.connect.data.Struct.getBoolean()方法的一些代码示例,展示了Struct.getBoolean()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Struct.getBoolean()方法的具体详情如下:
包路径:org.apache.kafka.connect.data.Struct
类名称:Struct
方法名:getBoolean

Struct.getBoolean介绍

[英]Equivalent to calling #get(String) and casting the result to a Boolean.
[中]相当于调用#get(String)并将结果转换为布尔值。

代码示例

代码示例来源:origin: debezium/debezium

private void changeSourceToLastSnapshotRecord(SourceRecord currentRecord) {
  final Struct envelope = (Struct)currentRecord.value();
  final Struct source = (Struct)envelope.get("source");
  if (source.getBoolean(SourceInfo.LAST_SNAPSHOT_RECORD_KEY) != null) {
    source.put(SourceInfo.LAST_SNAPSHOT_RECORD_KEY, true);
  }
}

代码示例来源:origin: debezium/debezium

protected void verifyFromInitialSync(SourceRecord record, AtomicBoolean foundLast) {
  if (record.sourceOffset().containsKey(SourceInfo.INITIAL_SYNC)) {
    assertThat(record.sourceOffset().containsKey(SourceInfo.INITIAL_SYNC)).isTrue();
    Struct value = (Struct) record.value();
    assertThat(value.getStruct(Envelope.FieldName.SOURCE).getBoolean(SourceInfo.INITIAL_SYNC)).isTrue();
  } else {
    // Only the last record in the initial sync should be marked as not being part of the initial sync ...
    assertThat(foundLast.getAndSet(true)).isFalse();
  }
}

代码示例来源:origin: debezium/debezium

protected void verifyNotFromInitialSync(SourceRecord record) {
  assertThat(record.sourceOffset().containsKey(SourceInfo.INITIAL_SYNC)).isFalse();
  Struct value = (Struct) record.value();
  assertThat(value.getStruct(Envelope.FieldName.SOURCE).getBoolean(SourceInfo.INITIAL_SYNC)).isNull();
}

代码示例来源:origin: debezium/debezium

protected void assertRecordOffsetAndSnapshotSource(SourceRecord record, boolean shouldBeSnapshot, boolean shouldBeLastSnapshotRecord) {
  Map<String, ?> offset = record.sourceOffset();
  assertNotNull(offset.get(SourceInfo.TXID_KEY));
  assertNotNull(offset.get(SourceInfo.TIMESTAMP_KEY));
  assertNotNull(offset.get(SourceInfo.LSN_KEY));
  Object snapshot = offset.get(SourceInfo.SNAPSHOT_KEY);
  Object lastSnapshotRecord = offset.get(SourceInfo.LAST_SNAPSHOT_RECORD_KEY);
  if (shouldBeSnapshot) {
    assertTrue("Snapshot marker expected but not found", (Boolean) snapshot);
    assertEquals("Last snapshot record marker mismatch", shouldBeLastSnapshotRecord, lastSnapshotRecord);
  }
  else {
    assertNull("Snapshot marker not expected, but found", snapshot);
    assertNull("Last snapshot marker not expected, but found", lastSnapshotRecord);
  }
  final Struct envelope = (Struct)record.value();
  if (envelope != null) {
    final Struct source = (Struct)envelope.get("source");
    final Boolean sourceSnapshot = source.getBoolean(SourceInfo.SNAPSHOT_KEY);
    final Boolean sourceLastSnapshotRecord = source.getBoolean(SourceInfo.LAST_SNAPSHOT_RECORD_KEY);
    if (shouldBeSnapshot) {
      assertTrue("Snapshot marker expected in source but not found", sourceSnapshot);
      assertEquals("Last snapshot record marker in source mismatch", shouldBeLastSnapshotRecord, sourceLastSnapshotRecord);
    }
    else {
      assertNull("Source snapshot marker not expected, but found", sourceSnapshot);
      assertNull("Source last snapshot marker not expected, but found", sourceLastSnapshotRecord);
    }
  }
}

代码示例来源:origin: debezium/debezium

assertThat(struct.getString(SourceInfo.REPLICA_SET_NAME)).isEqualTo(REPLICA_SET_NAME);
assertThat(struct.getString(SourceInfo.SERVER_NAME)).isEqualTo("serverX");
assertThat(struct.getBoolean(SourceInfo.INITIAL_SYNC)).isNull();

代码示例来源:origin: debezium/debezium

@Test
public void shouldReturnRecordedOffsetForUsedReplicaName() {
  Document event = new Document().append("ts", new BsonTimestamp(100, 2))
                  .append("h", Long.valueOf(1987654321))
                  .append("ns", "dbA.collectA");
  assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
  source.offsetStructForEvent(REPLICA_SET_NAME, event);
  assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(true);
  Map<String, ?> offset = source.lastOffset(REPLICA_SET_NAME);
  assertThat(offset.get(SourceInfo.TIMESTAMP)).isEqualTo(100);
  assertThat(offset.get(SourceInfo.ORDER)).isEqualTo(2);
  assertThat(offset.get(SourceInfo.OPERATION_ID)).isEqualTo(1987654321L);
  BsonTimestamp ts = source.lastOffsetTimestamp(REPLICA_SET_NAME);
  assertThat(ts.getTime()).isEqualTo(100);
  assertThat(ts.getInc()).isEqualTo(2);
  Struct struct = source.lastOffsetStruct(REPLICA_SET_NAME,new CollectionId(REPLICA_SET_NAME,"dbA","collectA"));
  assertThat(struct.getInt32(SourceInfo.TIMESTAMP)).isEqualTo(100);
  assertThat(struct.getInt32(SourceInfo.ORDER)).isEqualTo(2);
  assertThat(struct.getInt64(SourceInfo.OPERATION_ID)).isEqualTo(1987654321L);
  assertThat(struct.getString(SourceInfo.NAMESPACE)).isEqualTo("dbA.collectA");
  assertThat(struct.getString(SourceInfo.REPLICA_SET_NAME)).isEqualTo(REPLICA_SET_NAME);
  assertThat(struct.getString(SourceInfo.SERVER_NAME)).isEqualTo("serverX");
  assertThat(struct.getBoolean(SourceInfo.INITIAL_SYNC)).isNull();
}

代码示例来源:origin: debezium/debezium

@Test
public void shouldReturnRecordedOffsetForUsedReplicaNameDuringInitialSync() {
  source.startInitialSync(REPLICA_SET_NAME);
  Document event = new Document().append("ts", new BsonTimestamp(100, 2))
                  .append("h", Long.valueOf(1987654321))
                  .append("ns", "dbA.collectA");
  assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
  source.offsetStructForEvent(REPLICA_SET_NAME, event);
  assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(true);
  Map<String, ?> offset = source.lastOffset(REPLICA_SET_NAME);
  assertThat(offset.get(SourceInfo.TIMESTAMP)).isEqualTo(100);
  assertThat(offset.get(SourceInfo.ORDER)).isEqualTo(2);
  assertThat(offset.get(SourceInfo.OPERATION_ID)).isEqualTo(1987654321L);
  BsonTimestamp ts = source.lastOffsetTimestamp(REPLICA_SET_NAME);
  assertThat(ts.getTime()).isEqualTo(100);
  assertThat(ts.getInc()).isEqualTo(2);
  Struct struct = source.lastOffsetStruct(REPLICA_SET_NAME,new CollectionId(REPLICA_SET_NAME,"dbA","collectA"));
  assertThat(struct.getInt32(SourceInfo.TIMESTAMP)).isEqualTo(100);
  assertThat(struct.getInt32(SourceInfo.ORDER)).isEqualTo(2);
  assertThat(struct.getInt64(SourceInfo.OPERATION_ID)).isEqualTo(1987654321L);
  assertThat(struct.getString(SourceInfo.NAMESPACE)).isEqualTo("dbA.collectA");
  assertThat(struct.getString(SourceInfo.REPLICA_SET_NAME)).isEqualTo(REPLICA_SET_NAME);
  assertThat(struct.getString(SourceInfo.SERVER_NAME)).isEqualTo("serverX");
  assertThat(struct.getBoolean(SourceInfo.INITIAL_SYNC)).isEqualTo(true);
}

代码示例来源:origin: debezium/debezium

@Test
public void shouldReturnOffsetForUnusedReplicaName() {
  assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
  Map<String, ?> offset = source.lastOffset(REPLICA_SET_NAME);
  assertThat(offset.get(SourceInfo.TIMESTAMP)).isEqualTo(0);
  assertThat(offset.get(SourceInfo.ORDER)).isEqualTo(0);
  assertThat(offset.get(SourceInfo.OPERATION_ID)).isNull();
  BsonTimestamp ts = source.lastOffsetTimestamp(REPLICA_SET_NAME);
  assertThat(ts.getTime()).isEqualTo(0);
  assertThat(ts.getInc()).isEqualTo(0);
  Struct struct = source.lastOffsetStruct(REPLICA_SET_NAME,new CollectionId(REPLICA_SET_NAME,"dbA","collectA"));
  assertThat(struct.getInt32(SourceInfo.TIMESTAMP)).isEqualTo(0);
  assertThat(struct.getInt32(SourceInfo.ORDER)).isEqualTo(0);
  assertThat(struct.getInt64(SourceInfo.OPERATION_ID)).isNull();
  assertThat(struct.getString(SourceInfo.NAMESPACE)).isEqualTo("dbA.collectA");
  assertThat(struct.getString(SourceInfo.REPLICA_SET_NAME)).isEqualTo(REPLICA_SET_NAME);
  assertThat(struct.getString(SourceInfo.SERVER_NAME)).isEqualTo("serverX");
  assertThat(struct.getBoolean(SourceInfo.INITIAL_SYNC)).isNull();
  assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
}

代码示例来源:origin: debezium/debezium

@Test
public void shouldReturnOffsetForUnusedReplicaNameDuringInitialSync() {
  source.startInitialSync(REPLICA_SET_NAME);
  assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
  Map<String, ?> offset = source.lastOffset(REPLICA_SET_NAME);
  assertThat(offset.get(SourceInfo.TIMESTAMP)).isEqualTo(0);
  assertThat(offset.get(SourceInfo.ORDER)).isEqualTo(0);
  assertThat(offset.get(SourceInfo.OPERATION_ID)).isNull();
  BsonTimestamp ts = source.lastOffsetTimestamp(REPLICA_SET_NAME);
  assertThat(ts.getTime()).isEqualTo(0);
  assertThat(ts.getInc()).isEqualTo(0);
  Struct struct = source.lastOffsetStruct(REPLICA_SET_NAME,new CollectionId(REPLICA_SET_NAME,"dbA","collectA"));
  assertThat(struct.getInt32(SourceInfo.TIMESTAMP)).isEqualTo(0);
  assertThat(struct.getInt32(SourceInfo.ORDER)).isEqualTo(0);
  assertThat(struct.getInt64(SourceInfo.OPERATION_ID)).isNull();
  assertThat(struct.getString(SourceInfo.NAMESPACE)).isEqualTo("dbA.collectA");
  assertThat(struct.getString(SourceInfo.REPLICA_SET_NAME)).isEqualTo(REPLICA_SET_NAME);
  assertThat(struct.getString(SourceInfo.SERVER_NAME)).isEqualTo("serverX");
  assertThat(struct.getBoolean(SourceInfo.INITIAL_SYNC)).isEqualTo(true);
  assertThat(source.hasOffset(REPLICA_SET_NAME)).isEqualTo(false);
}

代码示例来源:origin: debezium/debezium

assertThat(secondToLast.sourceOffset().containsKey(SourceInfo.SNAPSHOT_KEY)).isTrue();
assertThat(((Struct) secondToLast.value()).getStruct(Envelope.FieldName.SOURCE).getBoolean(SourceInfo.SNAPSHOT_KEY)).isTrue();
assertThat(((Struct) last.value()).getStruct(Envelope.FieldName.SOURCE).getBoolean(SourceInfo.SNAPSHOT_KEY)).isTrue();

代码示例来源:origin: debezium/debezium

Boolean c1 = after.getBoolean("c1");
assertThat(c1).isEqualTo(Boolean.TRUE);

代码示例来源:origin: io.debezium/debezium-connector-postgres

private void changeSourceToLastSnapshotRecord(SourceRecord currentRecord) {
  final Struct envelope = (Struct)currentRecord.value();
  final Struct source = (Struct)envelope.get("source");
  if (source.getBoolean(SourceInfo.LAST_SNAPSHOT_RECORD_KEY) != null) {
    source.put(SourceInfo.LAST_SNAPSHOT_RECORD_KEY, true);
  }
}

代码示例来源:origin: io.debezium/debezium-connector-postgres

protected void assertRecordOffsetAndSnapshotSource(SourceRecord record, boolean shouldBeSnapshot, boolean shouldBeLastSnapshotRecord) {
  Map<String, ?> offset = record.sourceOffset();
  assertNotNull(offset.get(SourceInfo.TXID_KEY));
  assertNotNull(offset.get(SourceInfo.TIMESTAMP_KEY));
  assertNotNull(offset.get(SourceInfo.LSN_KEY));
  Object snapshot = offset.get(SourceInfo.SNAPSHOT_KEY);
  Object lastSnapshotRecord = offset.get(SourceInfo.LAST_SNAPSHOT_RECORD_KEY);
  if (shouldBeSnapshot) {
    assertTrue("Snapshot marker expected but not found", (Boolean) snapshot);
    assertEquals("Last snapshot record marker mismatch", shouldBeLastSnapshotRecord, lastSnapshotRecord);
  }
  else {
    assertNull("Snapshot marker not expected, but found", snapshot);
    assertNull("Last snapshot marker not expected, but found", lastSnapshotRecord);
  }
  final Struct envelope = (Struct)record.value();
  if (envelope != null) {
    final Struct source = (Struct)envelope.get("source");
    final Boolean sourceSnapshot = source.getBoolean(SourceInfo.SNAPSHOT_KEY);
    final Boolean sourceLastSnapshotRecord = source.getBoolean(SourceInfo.LAST_SNAPSHOT_RECORD_KEY);
    if (shouldBeSnapshot) {
      assertTrue("Snapshot marker expected in source but not found", sourceSnapshot);
      assertEquals("Last snapshot record marker in source mismatch", shouldBeLastSnapshotRecord, sourceLastSnapshotRecord);
    }
    else {
      assertNull("Source snapshot marker not expected, but found", sourceSnapshot);
      assertNull("Source last snapshot marker not expected, but found", sourceLastSnapshotRecord);
    }
  }
}

代码示例来源:origin: io.debezium/debezium-connector-mysql

assertThat(secondToLast.sourceOffset().containsKey(SourceInfo.SNAPSHOT_KEY)).isTrue();
assertThat(((Struct) secondToLast.value()).getStruct(Envelope.FieldName.SOURCE).getBoolean(SourceInfo.SNAPSHOT_KEY)).isTrue();
assertThat(((Struct) last.value()).getStruct(Envelope.FieldName.SOURCE).getBoolean(SourceInfo.SNAPSHOT_KEY)).isTrue();

代码示例来源:origin: io.debezium/debezium-connector-mysql

Boolean c1 = after.getBoolean("c1");
assertThat(c1).isEqualTo(Boolean.TRUE);

相关文章