本文整理汇总了Java中kafka.utils.MockTime类的典型用法代码示例。如果您正苦于以下问题:Java MockTime类的具体用法?Java MockTime怎么用?Java MockTime使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MockTime类属于kafka.utils包,在下文中一共展示了MockTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import kafka.utils.MockTime; //导入依赖的package包/类
public void initialize() {
if (initialized) {
throw new IllegalStateException("Context has been already initialized");
}
zkServer = new EmbeddedZookeeper(TestZKUtils.zookeeperConnect());
zkClient = new ZkClient(zkServer.connectString(), 10000, 10000, ZKStringSerializer$.MODULE$);
port = TestUtils.choosePort();
KafkaConfig config = new KafkaConfig(TestUtils.createBrokerConfig(brokerId, port, true));
Time mock = new MockTime();
kafkaServer = new KafkaServer(config, mock);
kafkaServer.startup();
initialized = true;
}
示例2: setUpClass
import kafka.utils.MockTime; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
// setup Zookeeper
zkServer = new EmbeddedZookeeper();
zkConnect = ZKHOST + ":" + zkServer.port();
zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
ZkUtils zkUtils = ZkUtils.apply(zkClient, false);
// setup Broker
Properties brokerProps = new Properties();
brokerProps.setProperty("zookeeper.connect", zkConnect);
brokerProps.setProperty("broker.id", "0");
brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafkaUtils-").toAbsolutePath().toString());
brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
KafkaConfig config = new KafkaConfig(brokerProps);
Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
// create topics
AdminUtils.createTopic(zkUtils, TOPIC_R, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);
AdminUtils.createTopic(zkUtils, TOPIC_S, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);
}
示例3: startKafkaBrokers
import kafka.utils.MockTime; //导入依赖的package包/类
public static void startKafkaBrokers(int numberOfBrokers) {
kafkaServers = new ArrayList<>(numberOfBrokers);
kafkaProps = new HashMap<>();
// setup Broker
StringBuilder sb = new StringBuilder();
for(int i = 0; i < numberOfBrokers; i ++) {
int port = TestUtils.choosePort();
Properties props = TestUtils.createBrokerConfig(i, port);
props.put("auto.create.topics.enable", "false");
kafkaServers.add(TestUtils.createServer(new KafkaConfig(props), new MockTime()));
sb.append("localhost:").append(port).append(",");
}
metadataBrokerURI = sb.deleteCharAt(sb.length()-1).toString();
LOG.info("Setting metadataBrokerList and auto.offset.reset for test case");
kafkaProps.put("auto.offset.reset", "smallest");
}
示例4: setUpClass
import kafka.utils.MockTime; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
// setup Zookeeper
zkServer = new EmbeddedZookeeper();
zkConnect = ZKHOST + ":" + zkServer.port();
zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
ZkUtils zkUtils = ZkUtils.apply(zkClient, false);
// setup Broker
Properties brokerProps = new Properties();
brokerProps.setProperty("zookeeper.connect", zkConnect);
brokerProps.setProperty("broker.id", "0");
brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
KafkaConfig config = new KafkaConfig(brokerProps);
Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
// create topic
AdminUtils.createTopic(zkUtils, TOPIC, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);
}
示例5: start
import kafka.utils.MockTime; //导入依赖的package包/类
public void start() throws IOException {
String zkConnect = TestZKUtils.zookeeperConnect();
zkServer = new EmbeddedZookeeper(zkConnect);
zkClient =
new ZkClient(zkServer.connectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
brokerPort = TestUtils.choosePort();
logger.info("{}", brokerPort);;
Properties props = TestUtils.createBrokerConfig(BROKER_ID, brokerPort, true);
// props.setProperty("zookeeper.connect", String.valueOf(zkPort));
props.setProperty("zookeeper.session.timeout.ms", "30000");
props.setProperty("zookeeper.connection.timeout.ms", "30000");
logger.info("{}", props);
KafkaConfig config = new KafkaConfig(props);
Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
}
示例6: startServer
import kafka.utils.MockTime; //导入依赖的package包/类
public static void startServer() throws RuntimeException {
if ( serverStarted && serverClosed ) {
throw new RuntimeException("Kafka test server has already been closed. Cannot generate Kafka server twice.");
}
if (!serverStarted) {
serverStarted = true;
zkConnect = TestZKUtils.zookeeperConnect();
zkServer = new EmbeddedZookeeper(zkConnect);
zkClient = new ZkClient(zkServer.connectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
kafkaPort = TestUtils.choosePort();
Properties props = TestUtils.createBrokerConfig(brokerId, kafkaPort, true);
KafkaConfig config = new KafkaConfig(props);
Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
}
}
示例7: createKafkaCluster
import kafka.utils.MockTime; //导入依赖的package包/类
public final String createKafkaCluster() throws IOException {
System.setProperty("zookeeper.preAllocSize", Integer.toString(128));
zkServer = new EmbeddedZookeeper();
String zkConnect = ZK_HOST + ':' + zkServer.port();
ZkClient zkClient = new ZkClient(zkConnect, SESSION_TIMEOUT, CONNECTION_TIMEOUT, ZKStringSerializer$.MODULE$);
zkUtils = ZkUtils.apply(zkClient, false);
brokerPort = getRandomPort();
Properties brokerProps = new Properties();
brokerProps.setProperty("zookeeper.connect", zkConnect);
brokerProps.setProperty("broker.id", "0");
brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKER_HOST + ':' + brokerPort);
brokerProps.setProperty("offsets.topic.replication.factor", "1");
brokerProps.setProperty("offsets.topic.num.partitions", "1");
// we need this due to avoid OOME while running tests, see https://issues.apache.org/jira/browse/KAFKA-3872
brokerProps.setProperty("log.cleaner.dedupe.buffer.size", Long.toString(2 * 1024 * 1024L));
KafkaConfig config = new KafkaConfig(brokerProps);
Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
return BROKER_HOST + ':' + brokerPort;
}
示例8: setUpClass
import kafka.utils.MockTime; //导入依赖的package包/类
@BeforeClass
public static void setUpClass() throws IOException {
// setup Zookeeper
zkServer = new EmbeddedZookeeper();
zkConnect = ZKHOST + ":" + zkServer.port();
zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
ZkUtils zkUtils = ZkUtils.apply(zkClient, false);
// setup Broker
Properties brokerProps = new Properties();
brokerProps.setProperty("zookeeper.connect", zkConnect);
brokerProps.setProperty("broker.id", "0");
brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
KafkaConfig config = new KafkaConfig(brokerProps);
Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
// create topics
AdminUtils.createTopic(zkUtils, TOPIC_OOS, 1, 1, new Properties(), RackAwareMode.Disabled$.MODULE$);
}
示例9: startup
import kafka.utils.MockTime; //导入依赖的package包/类
/**
* Starts the Embedded Kafka and Zookeeper Servers.
* @throws Exception - If an exeption occurs during startup.
*/
protected void startup() throws Exception {
// Setup the embedded zookeeper
logger.info("Starting up Embedded Zookeeper...");
zkServer = new EmbeddedZookeeper();
zookeperConnect = ZKHOST + ":" + zkServer.port();
logger.info("Embedded Zookeeper started at: {}", zookeperConnect);
// setup Broker
logger.info("Starting up Embedded Kafka...");
brokerPort = Integer.toString(PortUtils.getRandomFreePort());
final Properties brokerProps = new Properties();
brokerProps.setProperty(KafkaConfig$.MODULE$.BrokerIdProp(), "0");
brokerProps.setProperty(KafkaConfig$.MODULE$.HostNameProp(), BROKERHOST);
brokerProps.setProperty(KafkaConfig$.MODULE$.PortProp(), brokerPort);
brokerProps.setProperty(KafkaConfig$.MODULE$.ZkConnectProp(), zookeperConnect);
brokerProps.setProperty(KafkaConfig$.MODULE$.LogDirsProp(), Files.createTempDirectory(getClass().getSimpleName() + "-").toAbsolutePath().toString());
final KafkaConfig config = new KafkaConfig(brokerProps);
final Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
logger.info("Embedded Kafka Server started at: {}:{}", BROKERHOST, brokerPort);
}
示例10: setupKafka
import kafka.utils.MockTime; //导入依赖的package包/类
/**
* setup mini kafka and call the super to setup mini fluo
*/
@Before
public void setupKafka() throws Exception {
// Install an instance of Rya on the Accumulo cluster.
installRyaInstance();
// Setup Kafka.
zkServer = new EmbeddedZookeeper();
final String zkConnect = ZKHOST + ":" + zkServer.port();
zkClient = new ZkClient(zkConnect, 30000, 30000, ZKStringSerializer$.MODULE$);
zkUtils = ZkUtils.apply(zkClient, false);
// setup Broker
final Properties brokerProps = new Properties();
brokerProps.setProperty("zookeeper.connect", zkConnect);
brokerProps.setProperty("broker.id", "0");
brokerProps.setProperty("log.dirs", Files.createTempDirectory("kafka-").toAbsolutePath().toString());
brokerProps.setProperty("listeners", "PLAINTEXT://" + BROKERHOST + ":" + BROKERPORT);
final KafkaConfig config = new KafkaConfig(brokerProps);
final Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
}
示例11: startServer
import kafka.utils.MockTime; //导入依赖的package包/类
public static void startServer() throws RuntimeException {
if (serverStarted && serverClosed) {
throw new RuntimeException("Kafka test server has already been closed. Cannot generate Kafka server twice.");
}
if (!serverStarted) {
serverStarted = true;
zkConnect = TestZKUtils.zookeeperConnect();
zkServer = new EmbeddedZookeeper(zkConnect);
zkClient = new ZkClient(zkServer.connectString(), 30000, 30000, ZKStringSerializer$.MODULE$);
kafkaPort = TestUtils.choosePort();
Properties props = TestUtils.createBrokerConfig(brokerId, kafkaPort, true);
KafkaConfig config = new KafkaConfig(props);
Time mock = new MockTime();
kafkaServer = TestUtils.createServer(config, mock);
}
}
示例12: start
import kafka.utils.MockTime; //导入依赖的package包/类
void start()
throws RuntimeException {
if (_numStarted.incrementAndGet() == 1) {
log.warn("Starting up Kafka server suite. Zk at " + _zkConnectString + "; Kafka server at " + _kafkaServerPort);
_zkServer = new EmbeddedZookeeper(_zkConnectString);
_zkClient = new ZkClient(_zkConnectString, 30000, 30000, ZKStringSerializer$.MODULE$);
Properties props = kafka.utils.TestUtils.createBrokerConfig(_brokerId, _kafkaServerPort, true);
props.setProperty("zookeeper.connect", _zkConnectString);
KafkaConfig config = new KafkaConfig(props);
Time mock = new MockTime();
_kafkaServer = kafka.utils.TestUtils.createServer(config, mock);
}
else
{
log.info("Kafka server suite already started... continuing");
}
}
示例13: createKafkaServer
import kafka.utils.MockTime; //导入依赖的package包/类
private KafkaServer createKafkaServer(int brokerId,String _zkConnectString){
int _brokerId = brokerId;
int _kafkaServerPort = TestUtils.findFreePort();
Properties props = kafka.utils.TestUtils.createBrokerConfig(
_brokerId,
_zkConnectString,
kafka.utils.TestUtils.createBrokerConfig$default$3(),
kafka.utils.TestUtils.createBrokerConfig$default$4(),
_kafkaServerPort,
kafka.utils.TestUtils.createBrokerConfig$default$6(),
kafka.utils.TestUtils.createBrokerConfig$default$7(),
kafka.utils.TestUtils.createBrokerConfig$default$8(),
kafka.utils.TestUtils.createBrokerConfig$default$9(),
kafka.utils.TestUtils.createBrokerConfig$default$10(),
kafka.utils.TestUtils.createBrokerConfig$default$11(),
kafka.utils.TestUtils.createBrokerConfig$default$12(),
kafka.utils.TestUtils.createBrokerConfig$default$13(),
kafka.utils.TestUtils.createBrokerConfig$default$14()
);
KafkaConfig config = new KafkaConfig(props);
Time mock = new MockTime();
KafkaServer _kafkaServer = kafka.utils.TestUtils.createServer(config, mock);
kafkaBrokerPortList.add(_kafkaServerPort);
return _kafkaServer;
}
示例14: EmbeddedKafkaCluster
import kafka.utils.MockTime; //导入依赖的package包/类
public EmbeddedKafkaCluster(final int numBrokers,
final Properties brokerConfig,
final long mockTimeMillisStart,
final long mockTimeNanoStart) {
brokers = new KafkaEmbedded[numBrokers];
this.brokerConfig = brokerConfig;
time = new MockTime(mockTimeMillisStart, mockTimeNanoStart);
}
示例15: KafkaEmbedded
import kafka.utils.MockTime; //导入依赖的package包/类
/**
* Creates and starts an embedded Kafka broker.
*
* @param config Broker configuration settings. Used to modify, for example, on which port the
* broker should listen to. Note that you cannot change the `log.dirs` setting
* currently.
*/
public KafkaEmbedded(final Properties config, final MockTime time) throws IOException {
tmpFolder = new TemporaryFolder();
tmpFolder.create();
logDir = tmpFolder.newFolder();
effectiveConfig = effectiveConfigFrom(config);
final boolean loggingEnabled = true;
final KafkaConfig kafkaConfig = new KafkaConfig(effectiveConfig, loggingEnabled);
log.debug("Starting embedded Kafka broker (with log.dirs={} and ZK ensemble at {}) ...",
logDir, zookeeperConnect());
kafka = TestUtils.createServer(kafkaConfig, time);
log.debug("Startup of embedded Kafka broker at {} completed (with ZK ensemble at {}) ...",
brokerList(), zookeeperConnect());
}