use of kafka.utils.MockTime in project Gaffer by gchq.
the class AddElementsFromKafkaHandlerIT method before.
@BeforeEach
public void before() throws Exception {
bootstrapServers = "localhost:" + getOpenPort();
// Create zookeeper server
zkServer = new TestingServer(-1, createTemporaryDirectory("zkTmpDir"));
zkServer.start();
testFileSink = createTestFileSink();
// Create kafka server
kafkaServer = TestUtils.createServer(new KafkaConfig(serverProperties()), new MockTime());
MapStore.resetStaticMap();
}
use of kafka.utils.MockTime in project incubator-gobblin by apache.
the class KafkaTestBase method startServer.
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);
}
}
use of kafka.utils.MockTime in project incubator-rya by apache.
the class EmbeddedKafkaInstance method startup.
/**
* 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());
brokerProps.setProperty(KafkaConfig$.MODULE$.DeleteTopicEnableProp(), "true");
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);
}
use of kafka.utils.MockTime in project cruise-control by linkedin.
the class UserTaskManagerTest method testMaximumActiveTasks.
@Test
public void testMaximumActiveTasks() {
HttpSession mockHttpSession1 = EasyMock.mock(HttpSession.class);
EasyMock.expect(mockHttpSession1.getLastAccessedTime()).andReturn(100L).anyTimes();
HttpServletRequest mockHttpServletRequest1 = prepareRequest(mockHttpSession1, null);
OperationFuture future = new OperationFuture("future");
UserTaskManager userTaskManager = new UserTaskManager(1000, 1, TimeUnit.HOURS.toMillis(6), 100, new MockTime());
HttpServletResponse mockHttpServletResponse = EasyMock.mock(HttpServletResponse.class);
mockHttpServletResponse.setHeader(EasyMock.anyString(), EasyMock.anyString());
EasyMock.replay(mockHttpSession1, mockHttpServletResponse);
// test-case: test max limitation active tasks
OperationFuture future1 = userTaskManager.getOrCreateUserTask(mockHttpServletRequest1, mockHttpServletResponse, uuid -> future, 0, true, null).get(0);
Assert.assertEquals(future, future1);
EasyMock.verify(mockHttpSession1, mockHttpServletRequest1, mockHttpServletResponse);
HttpSession mockHttpSession2 = EasyMock.mock(HttpSession.class);
EasyMock.expect(mockHttpSession2.getLastAccessedTime()).andReturn(100L).anyTimes();
EasyMock.replay(mockHttpSession2);
EasyMock.reset(mockHttpServletResponse);
HttpServletRequest mockHttpServletRequest2 = prepareRequest(mockHttpSession2, null, "/test2", Collections.emptyMap());
try {
OperationFuture future2 = userTaskManager.getOrCreateUserTask(mockHttpServletRequest2, mockHttpServletResponse, uuid -> future, 0, true, null).get(0);
Assert.assertEquals(future, future2);
EasyMock.verify(mockHttpSession2, mockHttpServletRequest2, mockHttpServletResponse);
} catch (RuntimeException e) {
userTaskManager.close();
return;
}
Assert.fail("Don't expect to be here!");
}
use of kafka.utils.MockTime in project cruise-control by linkedin.
the class UserTaskManagerTest method testSessionsShareUserTask.
@Test
public void testSessionsShareUserTask() {
UUID testUserTaskId = UUID.randomUUID();
UserTaskManager.UuidGenerator mockUuidGenerator = EasyMock.mock(UserTaskManager.UuidGenerator.class);
EasyMock.expect(mockUuidGenerator.randomUUID()).andReturn(testUserTaskId).anyTimes();
HttpSession mockHttpSession = EasyMock.mock(HttpSession.class);
EasyMock.expect(mockHttpSession.getLastAccessedTime()).andReturn(100L).anyTimes();
Map<String, String[]> requestParams1 = new HashMap<>();
requestParams1.put("param", new String[] { "true" });
HttpServletRequest mockHttpServletRequest1 = prepareRequest(mockHttpSession, null, "test", requestParams1);
HttpServletResponse mockHttpServletResponse1 = EasyMock.mock(HttpServletResponse.class);
Capture<String> userTaskHeader = Capture.newInstance();
Capture<String> userTaskHeaderValue = Capture.newInstance();
mockHttpServletResponse1.setHeader(EasyMock.capture(userTaskHeader), EasyMock.capture(userTaskHeaderValue));
Map<String, String[]> requestParams2 = new HashMap<>();
requestParams2.put("param", new String[] { "true" });
HttpServletRequest mockHttpServletRequest2 = prepareRequest(mockHttpSession, null, "test", requestParams2);
HttpServletResponse mockHttpServletResponse2 = EasyMock.mock(HttpServletResponse.class);
mockHttpServletResponse2.setHeader(EasyMock.capture(userTaskHeader), EasyMock.capture(userTaskHeaderValue));
Map<String, String[]> requestParams3 = new HashMap<>();
requestParams3.put("param", new String[] { "true" });
HttpServletRequest mockHttpServletRequest3 = prepareRequest(mockHttpSession, testUserTaskId.toString(), "test", requestParams3);
HttpServletResponse mockHttpServletResponse3 = EasyMock.mock(HttpServletResponse.class);
mockHttpServletResponse3.setHeader(EasyMock.capture(userTaskHeader), EasyMock.capture(userTaskHeaderValue));
EasyMock.replay(mockUuidGenerator, mockHttpSession, mockHttpServletResponse1, mockHttpServletResponse2, mockHttpServletResponse3);
OperationFuture future = new OperationFuture("future");
UserTaskManager userTaskManager = new UserTaskManager(1000, 5, TimeUnit.HOURS.toMillis(6), 100, new MockTime(), mockUuidGenerator);
userTaskManager.getOrCreateUserTask(mockHttpServletRequest1, mockHttpServletResponse1, uuid -> future, 0, true, null);
userTaskManager.getOrCreateUserTask(mockHttpServletRequest2, mockHttpServletResponse2, uuid -> future, 0, true, null);
// Test UserTaskManger can recognize the previous created task by taskId.
userTaskManager.getOrCreateUserTask(mockHttpServletRequest3, mockHttpServletResponse3, uuid -> future, 0, true, null);
// The 2nd request should reuse the UserTask created for the 1st request since they use the same session and send the same request.
Assert.assertEquals(1, userTaskManager.numActiveSessionKeys());
EasyMock.verify(mockUuidGenerator, mockHttpServletResponse1, mockHttpServletResponse2, mockHttpServletResponse3, mockHttpServletRequest1, mockHttpServletRequest2, mockHttpServletRequest3);
}
Aggregations