@Before public void setupTest() { handler.clear(); }
@Test public void testCalls() { HttpPostClusterCallback callback = new HttpPostClusterCallback(); String base = "http://" + host + ":" + port; conf = Configuration.create(); conf.set(Constants.HttpCallback.START_URL, base + "/start/endpoint"); conf.set(Constants.HttpCallback.SUCCESS_URL, base + "/success/endpoint"); conf.set(Constants.HttpCallback.FAILURE_URL, base + "/failure/endpoint"); callback.initialize(conf); ClusterJob job = new ClusterJob(new JobId(cluster.getId(), 1), ClusterAction.CLUSTER_CREATE); CallbackData data = new CallbackData(CallbackData.Type.START, cluster, job); CallbackContext context = new CallbackContext(clusterStoreService, userStore, cluster.getAccount()); callback.onStart(data, context); callback.onSuccess(data, context); callback.onSuccess(data, context); callback.onFailure(data, context); Assert.assertEquals(handler.getStartCount(), 1); Assert.assertEquals(handler.getFailureCount(), 1); Assert.assertEquals(handler.getSuccessCount(), 2); }
@BeforeClass public static void setupTestClass() throws Exception { handler = new DummyHandler(); service = new DummyService(0, handler); service.startAndWait(); port = service.getBindAddress().getPort(); host = service.getBindAddress().getHostName(); clusterStoreService.getView(cluster.getAccount()).writeCluster(cluster); clusterStoreService.getSystemView().writeNode(Entities.ClusterExample.NODE1); clusterStoreService.getSystemView().writeNode(Entities.ClusterExample.NODE2); }
@Test public void testTriggers() { HttpPostClusterCallback callback = new HttpPostClusterCallback(); String base = "http://" + host + ":" + port; conf = Configuration.create(); conf.set(Constants.HttpCallback.START_URL, base + "/start/endpoint"); conf.set(Constants.HttpCallback.START_TRIGGERS, ClusterAction.CLUSTER_CONFIGURE.name()); callback.initialize(conf); // should not get triggered ClusterJob job = new ClusterJob(new JobId(cluster.getId(), 1), ClusterAction.CLUSTER_CREATE); CallbackData data = new CallbackData(CallbackData.Type.START, cluster, job); CallbackContext context = new CallbackContext(clusterStoreService, userStore, cluster.getAccount()); callback.onStart(data, context); Assert.assertEquals(0, handler.getStartCount()); // should get triggered job = new ClusterJob(new JobId(cluster.getId(), 1), ClusterAction.CLUSTER_CONFIGURE); data = new CallbackData(CallbackData.Type.START, cluster, job); callback.onStart(data, context); Assert.assertEquals(1, handler.getStartCount()); }