Search in sources :

Example 1 with MockClusterResourceListener

use of org.apache.kafka.test.MockClusterResourceListener in project apache-kafka-on-k8s by banzaicloud.

the class MetadataTest method testClusterListenerGetsNotifiedOfUpdate.

@Test
public void testClusterListenerGetsNotifiedOfUpdate() {
    long time = 0;
    MockClusterResourceListener mockClusterListener = new MockClusterResourceListener();
    ClusterResourceListeners listeners = new ClusterResourceListeners();
    listeners.maybeAdd(mockClusterListener);
    metadata = new Metadata(refreshBackoffMs, metadataExpireMs, true, false, listeners);
    String hostName = "www.example.com";
    Cluster cluster = Cluster.bootstrap(Arrays.asList(new InetSocketAddress(hostName, 9002)));
    metadata.update(cluster, Collections.<String>emptySet(), time);
    assertFalse("ClusterResourceListener should not called when metadata is updated with bootstrap Cluster", MockClusterResourceListener.IS_ON_UPDATE_CALLED.get());
    metadata.update(new Cluster("dummy", Arrays.asList(new Node(0, "host1", 1000)), Arrays.asList(new PartitionInfo("topic", 0, null, null, null), new PartitionInfo("topic1", 0, null, null, null)), Collections.<String>emptySet(), Collections.<String>emptySet()), Collections.<String>emptySet(), 100);
    assertEquals("MockClusterResourceListener did not get cluster metadata correctly", "dummy", mockClusterListener.clusterResource().clusterId());
    assertTrue("MockClusterResourceListener should be called when metadata is updated with non-bootstrap Cluster", MockClusterResourceListener.IS_ON_UPDATE_CALLED.get());
}
Also used : ClusterResourceListeners(org.apache.kafka.common.internals.ClusterResourceListeners) InetSocketAddress(java.net.InetSocketAddress) Node(org.apache.kafka.common.Node) MockClusterResourceListener(org.apache.kafka.test.MockClusterResourceListener) Cluster(org.apache.kafka.common.Cluster) PartitionInfo(org.apache.kafka.common.PartitionInfo) Test(org.junit.Test)

Example 2 with MockClusterResourceListener

use of org.apache.kafka.test.MockClusterResourceListener in project kafka by apache.

the class MetadataTest method testClusterListenerGetsNotifiedOfUpdate.

@Test
public void testClusterListenerGetsNotifiedOfUpdate() {
    MockClusterResourceListener mockClusterListener = new MockClusterResourceListener();
    ClusterResourceListeners listeners = new ClusterResourceListeners();
    listeners.maybeAdd(mockClusterListener);
    metadata = new Metadata(refreshBackoffMs, metadataExpireMs, new LogContext(), listeners);
    String hostName = "www.example.com";
    metadata.bootstrap(Collections.singletonList(new InetSocketAddress(hostName, 9002)));
    assertFalse(MockClusterResourceListener.IS_ON_UPDATE_CALLED.get(), "ClusterResourceListener should not called when metadata is updated with bootstrap Cluster");
    Map<String, Integer> partitionCounts = new HashMap<>();
    partitionCounts.put("topic", 1);
    partitionCounts.put("topic1", 1);
    MetadataResponse metadataResponse = RequestTestUtils.metadataUpdateWith("dummy", 1, partitionCounts);
    metadata.updateWithCurrentRequestVersion(metadataResponse, false, 100);
    assertEquals("dummy", mockClusterListener.clusterResource().clusterId(), "MockClusterResourceListener did not get cluster metadata correctly");
    assertTrue(MockClusterResourceListener.IS_ON_UPDATE_CALLED.get(), "MockClusterResourceListener should be called when metadata is updated with non-bootstrap Cluster");
}
Also used : ClusterResourceListeners(org.apache.kafka.common.internals.ClusterResourceListeners) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) MetadataResponse(org.apache.kafka.common.requests.MetadataResponse) MockClusterResourceListener(org.apache.kafka.test.MockClusterResourceListener) LogContext(org.apache.kafka.common.utils.LogContext) Test(org.junit.jupiter.api.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)2 ClusterResourceListeners (org.apache.kafka.common.internals.ClusterResourceListeners)2 MockClusterResourceListener (org.apache.kafka.test.MockClusterResourceListener)2 HashMap (java.util.HashMap)1 Cluster (org.apache.kafka.common.Cluster)1 Node (org.apache.kafka.common.Node)1 PartitionInfo (org.apache.kafka.common.PartitionInfo)1 MetadataResponse (org.apache.kafka.common.requests.MetadataResponse)1 LogContext (org.apache.kafka.common.utils.LogContext)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1