diff --git a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/ApplicationTestBase.java b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/ApplicationTestBase.java index 52b8e7997f..e93df64232 100644 --- a/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/ApplicationTestBase.java +++ b/eagle-core/eagle-app/eagle-app-base/src/main/java/org/apache/eagle/app/test/ApplicationTestBase.java @@ -1,60 +1,76 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - *

- * http://www.apache.org/licenses/LICENSE-2.0 - *

- * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.eagle.app.test; - -import com.google.inject.Guice; -import com.google.inject.Inject; -import com.google.inject.Injector; -import org.apache.eagle.metadata.model.ApplicationEntity; -import org.apache.eagle.metadata.service.ApplicationStatusUpdateService; -import org.junit.Assert; -import org.junit.Before; - -public class ApplicationTestBase { - private Injector injector; - - - @Inject - ApplicationStatusUpdateService statusUpdateService; - - @Before - public void setUp() { - injector = Guice.createInjector(new ApplicationTestGuiceModule()); - injector.injectMembers(this); - } - - protected Injector injector() { - return injector; - } - - protected void awaitApplicationStop(ApplicationEntity applicationEntity) throws InterruptedException { - int attempt = 0; - while (attempt < 10) { - attempt ++; - if (applicationEntity.getStatus() == ApplicationEntity.Status.STOPPED - || applicationEntity.getStatus() == ApplicationEntity.Status.INITIALIZED) { - break; - } else { - statusUpdateService.updateApplicationEntityStatus(applicationEntity); - Thread.sleep(1000); - } - } - if (attempt > 10) { - Assert.fail("Failed to wait for application to STOPPED after 10 attempts"); - } - } +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + *

+ * http://www.apache.org/licenses/LICENSE-2.0 + *

+ * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.eagle.app.test; + +import com.google.inject.Guice; +import com.google.inject.Inject; +import com.google.inject.Injector; +import org.apache.eagle.metadata.model.ApplicationEntity; +import org.apache.eagle.metadata.service.ApplicationStatusUpdateService; +import org.junit.Assert; +import org.junit.Before; + +public class ApplicationTestBase { + private Injector injector; + + + @Inject + ApplicationStatusUpdateService statusUpdateService; + + @Before + public void setUp() { + injector = Guice.createInjector(new ApplicationTestGuiceModule()); + injector.injectMembers(this); + } + + protected Injector injector() { + return injector; + } + + protected void awaitApplicationStop(ApplicationEntity applicationEntity) throws InterruptedException { + int attempt = 0; + while (attempt < 30) { + attempt ++; + if (applicationEntity.getStatus() == ApplicationEntity.Status.STOPPED + || applicationEntity.getStatus() == ApplicationEntity.Status.INITIALIZED) { + break; + } else { + statusUpdateService.updateApplicationEntityStatus(applicationEntity); + Thread.sleep(1000); + } + } + if (attempt >= 30) { + Assert.fail("Failed to wait for application to STOPPED after 10 attempts"); + } + } + + protected void awaitApplicationStatus(ApplicationEntity applicationEntity, ApplicationEntity.Status status) throws InterruptedException { + int attempt = 0; + while (attempt < 30) { + attempt ++; + if (applicationEntity.getStatus() == status) { + break; + } else { + statusUpdateService.updateApplicationEntityStatus(applicationEntity); + Thread.sleep(1000); + } + } + if (attempt >= 30) { + Assert.fail("Failed to wait for application to STOPPED after 10 attempts"); + } + } } \ No newline at end of file diff --git a/eagle-security/eagle-security-hdfs-auditlog/src/test/java/org/apache/eagle/security/auditlog/TestHdfsAuditLogApplication.java b/eagle-security/eagle-security-hdfs-auditlog/src/test/java/org/apache/eagle/security/auditlog/TestHdfsAuditLogApplication.java index 5e76fd8c38..67f2825ac2 100644 --- a/eagle-security/eagle-security-hdfs-auditlog/src/test/java/org/apache/eagle/security/auditlog/TestHdfsAuditLogApplication.java +++ b/eagle-security/eagle-security-hdfs-auditlog/src/test/java/org/apache/eagle/security/auditlog/TestHdfsAuditLogApplication.java @@ -38,8 +38,6 @@ public class TestHdfsAuditLogApplication extends ApplicationTestBase { private SiteResource siteResource; @Inject private ApplicationResource applicationResource; - @Inject - ApplicationStatusUpdateService statusUpdateService; @Test public void testHdfsAuditLogApplication() throws InterruptedException { @@ -57,7 +55,7 @@ public void testHdfsAuditLogApplication() throws InterruptedException { ApplicationEntity applicationEntity = applicationResource.installApplication(installOperation).getData(); // Start application applicationResource.startApplication(new ApplicationOperations.StartOperation(applicationEntity.getUuid())); - statusUpdateService.updateApplicationEntityStatus(applicationEntity); + awaitApplicationStatus(applicationEntity, ApplicationEntity.Status.RUNNING); // Stop application applicationResource.stopApplication(new ApplicationOperations.StopOperation(applicationEntity.getUuid())); awaitApplicationStop(applicationEntity);