|
|
@ -26,26 +26,44 @@ import kafka.zk.ZooKeeperTestHarness |
|
|
|
import junit.framework.Assert._ |
|
|
|
import junit.framework.Assert._ |
|
|
|
|
|
|
|
|
|
|
|
class ServerStartupTest extends JUnit3Suite with ZooKeeperTestHarness { |
|
|
|
class ServerStartupTest extends JUnit3Suite with ZooKeeperTestHarness { |
|
|
|
var server : KafkaServer = null |
|
|
|
|
|
|
|
val brokerId = 0 |
|
|
|
|
|
|
|
val zookeeperChroot = "/kafka-chroot-for-unittest" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override def setUp() { |
|
|
|
def testBrokerCreatesZKChroot { |
|
|
|
super.setUp() |
|
|
|
val brokerId = 0 |
|
|
|
|
|
|
|
val zookeeperChroot = "/kafka-chroot-for-unittest" |
|
|
|
val props = TestUtils.createBrokerConfig(brokerId, TestUtils.choosePort()) |
|
|
|
val props = TestUtils.createBrokerConfig(brokerId, TestUtils.choosePort()) |
|
|
|
val zooKeeperConnect = props.get("zookeeper.connect") |
|
|
|
val zooKeeperConnect = props.get("zookeeper.connect") |
|
|
|
props.put("zookeeper.connect", zooKeeperConnect + zookeeperChroot) |
|
|
|
props.put("zookeeper.connect", zooKeeperConnect + zookeeperChroot) |
|
|
|
server = TestUtils.createServer(new KafkaConfig(props)) |
|
|
|
val server = TestUtils.createServer(new KafkaConfig(props)) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
val pathExists = ZkUtils.pathExists(zkClient, zookeeperChroot) |
|
|
|
|
|
|
|
assertTrue(pathExists) |
|
|
|
|
|
|
|
|
|
|
|
override def tearDown() { |
|
|
|
|
|
|
|
server.shutdown() |
|
|
|
server.shutdown() |
|
|
|
Utils.rm(server.config.logDirs) |
|
|
|
Utils.rm(server.config.logDirs) |
|
|
|
super.tearDown() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
def testBrokerCreatesZKChroot { |
|
|
|
def testConflictBrokerRegistration { |
|
|
|
val pathExists = ZkUtils.pathExists(zkClient, zookeeperChroot) |
|
|
|
// Try starting a broker with the a conflicting broker id. |
|
|
|
assertTrue(pathExists) |
|
|
|
// This shouldn't affect the existing broker registration. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val brokerId = 0 |
|
|
|
|
|
|
|
val props1 = TestUtils.createBrokerConfig(brokerId) |
|
|
|
|
|
|
|
val server1 = TestUtils.createServer(new KafkaConfig(props1)) |
|
|
|
|
|
|
|
val brokerRegistration = ZkUtils.readData(zkClient, ZkUtils.BrokerIdsPath + "/" + brokerId)._1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
val props2 = TestUtils.createBrokerConfig(brokerId) |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
TestUtils.createServer(new KafkaConfig(props2)) |
|
|
|
|
|
|
|
fail("Registering a broker with a conflicting id should fail") |
|
|
|
|
|
|
|
} catch { |
|
|
|
|
|
|
|
case e : RuntimeException => |
|
|
|
|
|
|
|
// this is expected |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// broker registration shouldn't change |
|
|
|
|
|
|
|
assertEquals(brokerRegistration, ZkUtils.readData(zkClient, ZkUtils.BrokerIdsPath + "/" + brokerId)._1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server1.shutdown() |
|
|
|
|
|
|
|
Utils.rm(server1.config.logDirs) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |