Refactor the CheckHealthCommand and GetVmDiskStatsCommand classes in CitrixResourceBase

- Added basic tests for both wrappers
This commit is contained in:
wilderrodrigues 2015-03-24 11:05:43 +01:00
parent 8f04108e23
commit c7830efef5
5 changed files with 100 additions and 1 deletions

View File

@ -394,7 +394,7 @@ public abstract class CitrixResourceBase implements ServerResource, HypervisorRe
}
protected boolean pingXAPI() {
public boolean pingXAPI() {
final Connection conn = getConnection();
try {
final Host host = Host.getByUuid(conn, _host.getUuid());

View File

@ -0,0 +1,35 @@
//
// 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 com.cloud.hypervisor.xenserver.resource.wrapper;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckHealthAnswer;
import com.cloud.agent.api.CheckHealthCommand;
import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
import com.cloud.resource.CommandWrapper;
public final class CheckHealthCommandWrapper extends CommandWrapper<CheckHealthCommand, Answer, CitrixResourceBase> {
@Override
public Answer execute(final CheckHealthCommand command, final CitrixResourceBase citrixResourceBase) {
final boolean result = citrixResourceBase.pingXAPI();
return new CheckHealthAnswer(command, result);
}
}

View File

@ -22,8 +22,10 @@ package com.cloud.hypervisor.xenserver.resource.wrapper;
import java.util.Hashtable;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckHealthCommand;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.GetHostStatsCommand;
import com.cloud.agent.api.GetVmDiskStatsCommand;
import com.cloud.agent.api.GetVmStatsCommand;
import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.RebootRouterCommand;
@ -59,6 +61,8 @@ public class CitrixRequestWrapper extends RequestWrapper {
map.put(ReadyCommand.class, new CitrixReadyCommandWrapper());
map.put(GetHostStatsCommand.class, new GetHostStatsCommandWrapper());
map.put(GetVmStatsCommand.class, new GetVmStatsCommandWrapper());
map.put(GetVmDiskStatsCommand.class, new GetVmDiskStatsCommandWrapper());
map.put(CheckHealthCommand.class, new CheckHealthCommandWrapper());
}
public static CitrixRequestWrapper getInstance() {

View File

@ -0,0 +1,34 @@
//
// 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 com.cloud.hypervisor.xenserver.resource.wrapper;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.GetVmDiskStatsAnswer;
import com.cloud.agent.api.GetVmDiskStatsCommand;
import com.cloud.hypervisor.xenserver.resource.CitrixResourceBase;
import com.cloud.resource.CommandWrapper;
public final class GetVmDiskStatsCommandWrapper extends CommandWrapper<GetVmDiskStatsCommand, Answer, CitrixResourceBase> {
@Override
public Answer execute(final GetVmDiskStatsCommand command, final CitrixResourceBase citrixResourceBase) {
return new GetVmDiskStatsAnswer(command, null, null, null);
}
}

View File

@ -17,8 +17,10 @@ import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
import com.cloud.agent.api.Answer;
import com.cloud.agent.api.CheckHealthCommand;
import com.cloud.agent.api.Command;
import com.cloud.agent.api.GetHostStatsCommand;
import com.cloud.agent.api.GetVmDiskStatsCommand;
import com.cloud.agent.api.GetVmStatsCommand;
import com.cloud.agent.api.ReadyCommand;
import com.cloud.agent.api.RebootAnswer;
@ -151,6 +153,30 @@ public class CitrixRequestWrapperTest {
assertTrue(answer.getResult());
}
@Test
public void testGetVmDiskStatsCommandCommand() {
final GetVmDiskStatsCommand statsCommand = new GetVmDiskStatsCommand(new ArrayList<String>(), null, null);
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(statsCommand, citrixResourceBase);
assertTrue(answer.getResult());
}
@Test
public void testCheckHealthCommandCommand() {
final CheckHealthCommand statsCommand = new CheckHealthCommand();
final CitrixRequestWrapper wrapper = CitrixRequestWrapper.getInstance();
assertNotNull(wrapper);
final Answer answer = wrapper.execute(statsCommand, citrixResourceBase);
assertFalse(answer.getResult());
}
}
class NotAValidCommand extends Command {