Skip to content
This repository has been archived by the owner on May 12, 2021. It is now read-only.

Commit

Permalink
[MINOR] Fix TestHdfsAuditLogApplication by support await RUNNING
Browse files Browse the repository at this point in the history
Fix TestHdfsAuditLogApplication by supporting await RUNNING

Resolve Exception: App: HDFS_AUDIT_LOG_MONITOR_APP_TEST_SITE status is STOPPING, uninstall operation is not allowed

Author: Hao Chen <hao@apache.org>

Closes #818 from haoch/FixTestHdfsAuditLogApplication.
  • Loading branch information
haoch committed Feb 18, 2017
1 parent 71522d9 commit db26c1c
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down

0 comments on commit db26c1c

Please sign in to comment.