APISonar


org.apache.kafka.streams.integration.utils.EmbeddedKafkaCluster.time

> org > apache > kafka > streams > integration > utils > EmbeddedKafkaCluster > time
org APIs apache APIs kafka APIs streams APIs integration APIs utils APIs EmbeddedKafkaCluster APIs time APIs

Example 1
static EmbeddedKafkaCluster cluster;

    private boolean setCurrentTime() {
        boolean currentTimeSet = false;
        try {
            mockTime = cluster.time;
            // we align time to seconds to get clean window boundaries and thus ensure the same result for each run
            // otherwise, input records could fall into different windows for different runs depending on the initial mock time
            final long alignedTime = (System.currentTimeMillis() / 1000 + 1) * 1000;
            mockTime.setCurrentTimeMs(alignedTime);
            currentTimeSet = true;
        } catch (final IllegalArgumentException e) {
            // don't care will retry until set
        }
        return currentTimeSet;
    }
Example 2
public static final EmbeddedKafkaCluster CLUSTER = new EmbeddedKafkaCluster(
        NUM_BROKERS,
        Utils.mkProperties(Collections.singletonMap("auto.create.topics.enable", "false"))
    );

    private void writeInputData(final List<KeyValue<Long, Long>> records) throws Exception {
        IntegrationTestUtils.produceKeyValuesSynchronously(
            MULTI_PARTITION_INPUT_TOPIC,
            records,
            TestUtils.producerConfig(CLUSTER.bootstrapServers(), LongSerializer.class, LongSerializer.class),
            CLUSTER.time
        );
    }
Example 3
static EmbeddedKafkaCluster cluster;

    private void prepareEnvironment() {
        if (adminClient == null) {
            adminClient = AdminClient.create(commonClientConfig);
        }
        if (kafkaAdminClient == null) {
            kafkaAdminClient = (KafkaAdminClient) org.apache.kafka.clients.admin.AdminClient.create(commonClientConfig);
        }

        // we align time to seconds to get clean window boundaries and thus ensure the same result for each run
        // otherwise, input records could fall into different windows for different runs depending on the initial mock time
        final long alignedTime = (System.currentTimeMillis() / 1000 + 1) * 1000;
        mockTime = cluster.time;
        mockTime.setCurrentTimeMs(alignedTime);
    }