Search in sources :

Example 1 with ProducerConfiguration

use of io.streamnative.kafka.client.api.ProducerConfiguration in project starlight-for-kafka by datastax.

the class KafkaIdleConnectionTest method setup.

@BeforeClass
@Override
protected void setup() throws Exception {
    conf.setConnectionMaxIdleMs(DEFAULT_BROKER_CONNECTION_MAX_IDLE_MS);
    super.internalSetup();
    time = Time.SYSTEM;
    Metrics metrics = new Metrics(time);
    ProducerConfiguration producerConfiguration = ProducerConfiguration.builder().bootstrapServers("localhost:" + getKafkaBrokerPort()).keySerializer(KafkaVersion.DEFAULT.getStringSerializer()).valueSerializer(KafkaVersion.DEFAULT.getStringSerializer()).build();
    ChannelBuilder channelBuilder = ClientUtils.createChannelBuilder(new ProducerConfig(producerConfiguration.toProperties()));
    String clientId = "clientId";
    selector = new Selector(DEFAULT_CONNECTION_MAX_IDLE_MS, metrics, time, "test-selector", channelBuilder, new LogContext(String.format("[Test Selector clientId=%s] ", clientId)));
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) ProducerConfiguration(io.streamnative.kafka.client.api.ProducerConfiguration) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) LogContext(org.apache.kafka.common.utils.LogContext) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) Selector(org.apache.kafka.common.network.Selector) BeforeClass(org.testng.annotations.BeforeClass)

Example 2 with ProducerConfiguration

use of io.streamnative.kafka.client.api.ProducerConfiguration in project kop by streamnative.

the class DelayAuthorizationFailedCloseTest method setup.

@BeforeClass
@Override
protected void setup() throws Exception {
    SecretKey secretKey = AuthTokenUtils.createSecretKey(SignatureAlgorithm.HS256);
    AuthenticationProviderToken provider = new AuthenticationProviderToken();
    Properties properties = new Properties();
    properties.setProperty("tokenSecretKey", AuthTokenUtils.encodeKeyBase64(secretKey));
    ServiceConfiguration authConf = new ServiceConfiguration();
    authConf.setProperties(properties);
    provider.initialize(authConf);
    String adminToken = AuthTokenUtils.createToken(secretKey, ADMIN_USER, Optional.empty());
    super.resetConfig();
    conf.setSaslAllowedMechanisms(Sets.newHashSet("PLAIN"));
    conf.setKafkaMetadataTenant("internal");
    conf.setKafkaMetadataNamespace("__kafka");
    conf.setKafkaTenant(TENANT);
    conf.setKafkaNamespace(NAMESPACE);
    conf.setClusterName(super.configClusterName);
    conf.setAuthorizationEnabled(true);
    conf.setAuthenticationEnabled(true);
    conf.setAuthorizationAllowWildcardsMatching(true);
    conf.setSuperUserRoles(Sets.newHashSet(ADMIN_USER));
    conf.setAuthenticationProviders(Sets.newHashSet(AuthenticationProviderToken.class.getName()));
    conf.setBrokerClientAuthenticationPlugin(AuthenticationToken.class.getName());
    conf.setBrokerClientAuthenticationParameters("token:" + adminToken);
    conf.setProperties(properties);
    conf.setFailedAuthenticationDelayMs(FAILED_AUTHENTICATION_DELAY_MS);
    super.internalSetup();
    log.info("success internal setup");
    if (!admin.namespaces().getNamespaces(TENANT).contains(TENANT + "/__kafka")) {
        admin.namespaces().createNamespace(TENANT + "/__kafka");
        admin.namespaces().setNamespaceReplicationClusters(TENANT + "/__kafka", Sets.newHashSet("test"));
        admin.namespaces().setRetention(TENANT + "/__kafka", new RetentionPolicies(-1, -1));
    }
    log.info("created namespaces, init handler");
    time = Time.SYSTEM;
    Metrics metrics = new Metrics(time);
    ProducerConfiguration producerConfiguration = producerConfiguration();
    ChannelBuilder channelBuilder = ClientUtils.createChannelBuilder(new ProducerConfig(producerConfiguration.toProperties()));
    String clientId = "clientId";
    selector = new Selector(DEFAULT_CONNECTION_MAX_IDLE_MS, metrics, time, "test-selector", channelBuilder, new LogContext(String.format("[Test Selector clientId=%s] ", clientId)));
}
Also used : RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) AuthenticationToken(org.apache.pulsar.client.impl.auth.AuthenticationToken) AuthenticationProviderToken(org.apache.pulsar.broker.authentication.AuthenticationProviderToken) ProducerConfiguration(io.streamnative.kafka.client.api.ProducerConfiguration) LogContext(org.apache.kafka.common.utils.LogContext) Properties(java.util.Properties) SecretKey(javax.crypto.SecretKey) Metrics(org.apache.kafka.common.metrics.Metrics) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) Selector(org.apache.kafka.common.network.Selector) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with ProducerConfiguration

use of io.streamnative.kafka.client.api.ProducerConfiguration in project starlight-for-kafka by datastax.

the class DelayAuthorizationFailedCloseTest method setup.

@BeforeClass
@Override
protected void setup() throws Exception {
    SecretKey secretKey = AuthTokenUtils.createSecretKey(SignatureAlgorithm.HS256);
    AuthenticationProviderToken provider = new AuthenticationProviderToken();
    Properties properties = new Properties();
    properties.setProperty("tokenSecretKey", AuthTokenUtils.encodeKeyBase64(secretKey));
    ServiceConfiguration authConf = new ServiceConfiguration();
    authConf.setProperties(properties);
    provider.initialize(authConf);
    String adminToken = AuthTokenUtils.createToken(secretKey, ADMIN_USER, Optional.empty());
    super.resetConfig();
    conf.setSaslAllowedMechanisms(Sets.newHashSet("PLAIN"));
    conf.setKafkaMetadataTenant("internal");
    conf.setKafkaMetadataNamespace("__kafka");
    conf.setKafkaTenant(TENANT);
    conf.setKafkaNamespace(NAMESPACE);
    conf.setClusterName(super.configClusterName);
    conf.setAuthorizationEnabled(true);
    conf.setAuthenticationEnabled(true);
    conf.setAuthorizationAllowWildcardsMatching(true);
    conf.setSuperUserRoles(Sets.newHashSet(ADMIN_USER));
    conf.setAuthenticationProviders(Sets.newHashSet(AuthenticationProviderToken.class.getName()));
    conf.setBrokerClientAuthenticationPlugin(AuthenticationToken.class.getName());
    conf.setBrokerClientAuthenticationParameters("token:" + adminToken);
    conf.setProperties(properties);
    conf.setFailedAuthenticationDelayMs(FAILED_AUTHENTICATION_DELAY_MS);
    super.internalSetup();
    log.info("success internal setup");
    if (!admin.namespaces().getNamespaces(TENANT).contains(TENANT + "/__kafka")) {
        admin.namespaces().createNamespace(TENANT + "/__kafka");
        admin.namespaces().setNamespaceReplicationClusters(TENANT + "/__kafka", Sets.newHashSet("test"));
        admin.namespaces().setRetention(TENANT + "/__kafka", new RetentionPolicies(-1, -1));
    }
    log.info("created namespaces, init handler");
    time = Time.SYSTEM;
    Metrics metrics = new Metrics(time);
    ProducerConfiguration producerConfiguration = producerConfiguration();
    ChannelBuilder channelBuilder = ClientUtils.createChannelBuilder(new ProducerConfig(producerConfiguration.toProperties()));
    String clientId = "clientId";
    selector = new Selector(DEFAULT_CONNECTION_MAX_IDLE_MS, metrics, time, "test-selector", channelBuilder, new LogContext(String.format("[Test Selector clientId=%s] ", clientId)));
}
Also used : RetentionPolicies(org.apache.pulsar.common.policies.data.RetentionPolicies) AuthenticationToken(org.apache.pulsar.client.impl.auth.AuthenticationToken) AuthenticationProviderToken(org.apache.pulsar.broker.authentication.AuthenticationProviderToken) ProducerConfiguration(io.streamnative.kafka.client.api.ProducerConfiguration) LogContext(org.apache.kafka.common.utils.LogContext) Properties(java.util.Properties) SecretKey(javax.crypto.SecretKey) Metrics(org.apache.kafka.common.metrics.Metrics) ServiceConfiguration(org.apache.pulsar.broker.ServiceConfiguration) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) Selector(org.apache.kafka.common.network.Selector) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with ProducerConfiguration

use of io.streamnative.kafka.client.api.ProducerConfiguration in project kop by streamnative.

the class KafkaIdleConnectionTest method setup.

@BeforeClass
@Override
protected void setup() throws Exception {
    conf.setConnectionMaxIdleMs(DEFAULT_BROKER_CONNECTION_MAX_IDLE_MS);
    super.internalSetup();
    time = Time.SYSTEM;
    Metrics metrics = new Metrics(time);
    ProducerConfiguration producerConfiguration = ProducerConfiguration.builder().bootstrapServers("localhost:" + getKafkaBrokerPort()).keySerializer(KafkaVersion.DEFAULT.getStringSerializer()).valueSerializer(KafkaVersion.DEFAULT.getStringSerializer()).build();
    ChannelBuilder channelBuilder = ClientUtils.createChannelBuilder(new ProducerConfig(producerConfiguration.toProperties()));
    String clientId = "clientId";
    selector = new Selector(DEFAULT_CONNECTION_MAX_IDLE_MS, metrics, time, "test-selector", channelBuilder, new LogContext(String.format("[Test Selector clientId=%s] ", clientId)));
}
Also used : Metrics(org.apache.kafka.common.metrics.Metrics) ProducerConfiguration(io.streamnative.kafka.client.api.ProducerConfiguration) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) LogContext(org.apache.kafka.common.utils.LogContext) ChannelBuilder(org.apache.kafka.common.network.ChannelBuilder) Selector(org.apache.kafka.common.network.Selector) BeforeClass(org.testng.annotations.BeforeClass)

Aggregations

ProducerConfiguration (io.streamnative.kafka.client.api.ProducerConfiguration)4 ProducerConfig (org.apache.kafka.clients.producer.ProducerConfig)4 Metrics (org.apache.kafka.common.metrics.Metrics)4 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)4 Selector (org.apache.kafka.common.network.Selector)4 LogContext (org.apache.kafka.common.utils.LogContext)4 BeforeClass (org.testng.annotations.BeforeClass)4 Properties (java.util.Properties)2 SecretKey (javax.crypto.SecretKey)2 ServiceConfiguration (org.apache.pulsar.broker.ServiceConfiguration)2 AuthenticationProviderToken (org.apache.pulsar.broker.authentication.AuthenticationProviderToken)2 AuthenticationToken (org.apache.pulsar.client.impl.auth.AuthenticationToken)2 RetentionPolicies (org.apache.pulsar.common.policies.data.RetentionPolicies)2