use of org.apache.kafka.common.serialization.ByteArraySerializer in project kafka by apache.
the class KafkaProducerTest method testOsDefaultSocketBufferSizes.
@Test
public void testOsDefaultSocketBufferSizes() throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
config.put(ProducerConfig.SEND_BUFFER_CONFIG, Selectable.USE_DEFAULT_BUFFER_SIZE);
config.put(ProducerConfig.RECEIVE_BUFFER_CONFIG, Selectable.USE_DEFAULT_BUFFER_SIZE);
KafkaProducer<byte[], byte[]> producer = new KafkaProducer<>(config, new ByteArraySerializer(), new ByteArraySerializer());
producer.close();
}
use of org.apache.kafka.common.serialization.ByteArraySerializer in project kafka by apache.
the class KafkaProducerTest method testInvalidSocketSendBufferSize.
@Test(expected = KafkaException.class)
public void testInvalidSocketSendBufferSize() throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
config.put(ProducerConfig.SEND_BUFFER_CONFIG, -2);
new KafkaProducer<>(config, new ByteArraySerializer(), new ByteArraySerializer());
}
use of org.apache.kafka.common.serialization.ByteArraySerializer in project kafka by apache.
the class KafkaProducerTest method testInvalidSocketReceiveBufferSize.
@Test(expected = KafkaException.class)
public void testInvalidSocketReceiveBufferSize() throws Exception {
Map<String, Object> config = new HashMap<>();
config.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9999");
config.put(ProducerConfig.RECEIVE_BUFFER_CONFIG, -2);
new KafkaProducer<>(config, new ByteArraySerializer(), new ByteArraySerializer());
}
use of org.apache.kafka.common.serialization.ByteArraySerializer in project kafka by apache.
the class KafkaProducerTest method testConstructorFailureCloseResource.
@Test
public void testConstructorFailureCloseResource() {
Properties props = new Properties();
props.setProperty(ProducerConfig.CLIENT_ID_CONFIG, "testConstructorClose");
props.setProperty(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "some.invalid.hostname.foo.bar.local:9999");
props.setProperty(ProducerConfig.METRIC_REPORTER_CLASSES_CONFIG, MockMetricsReporter.class.getName());
final int oldInitCount = MockMetricsReporter.INIT_COUNT.get();
final int oldCloseCount = MockMetricsReporter.CLOSE_COUNT.get();
try {
KafkaProducer<byte[], byte[]> producer = new KafkaProducer<byte[], byte[]>(props, new ByteArraySerializer(), new ByteArraySerializer());
} catch (KafkaException e) {
Assert.assertEquals(oldInitCount + 1, MockMetricsReporter.INIT_COUNT.get());
Assert.assertEquals(oldCloseCount + 1, MockMetricsReporter.CLOSE_COUNT.get());
Assert.assertEquals("Failed to construct kafka producer", e.getMessage());
return;
}
fail("should have caught an exception and returned");
}
use of org.apache.kafka.common.serialization.ByteArraySerializer in project kafka by apache.
the class KafkaProducerTest method testConstructorWithSerializers.
@Test
public void testConstructorWithSerializers() {
Properties producerProps = new Properties();
producerProps.put(ProducerConfig.BOOTSTRAP_SERVERS_CONFIG, "localhost:9000");
new KafkaProducer<>(producerProps, new ByteArraySerializer(), new ByteArraySerializer()).close();
}
Aggregations