mirror of https://github.com/apache/cloudstack.git
add test
(cherry picked from commit d157e2970e)
Signed-off-by: animesh <animesh@apache.org>
This commit is contained in:
parent
60e68ab9ed
commit
5e013e9931
|
|
@ -185,12 +185,6 @@ public class ChildTestConfiguration extends TestConfiguration {
|
|||
return Mockito.mock(VirtualMachineManager.class);
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public SnapshotManager snapshotMgr() {
|
||||
return Mockito.mock(SnapshotManager.class);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ResourceManager resourceMgr() {
|
||||
return Mockito.mock(ResourceManager.class);
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
*/
|
||||
package org.apache.cloudstack.storage.test;
|
||||
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionStrategy;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreProvider;
|
||||
import org.apache.cloudstack.storage.datastore.provider.CloudStackPrimaryDataStoreProviderImpl;
|
||||
import org.apache.cloudstack.storage.datastore.type.DataStoreType;
|
||||
|
|
@ -35,4 +36,10 @@ public class FakeDriverTestConfiguration extends ChildTestConfiguration{
|
|||
return provider;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public DataMotionStrategy dataMotionStrategy() {
|
||||
DataMotionStrategy strategy = new MockStorageMotionStrategy();
|
||||
return strategy;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,7 +19,11 @@
|
|||
package org.apache.cloudstack.storage.test;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.cloud.agent.api.to.DataObjectType;
|
||||
import com.cloud.agent.api.to.DataTO;
|
||||
import com.cloud.storage.Storage;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.CopyCommandResult;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionStrategy;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataObject;
|
||||
|
|
@ -29,6 +33,9 @@ import org.apache.cloudstack.framework.async.AsyncCompletionCallback;
|
|||
|
||||
import com.cloud.agent.api.to.VirtualMachineTO;
|
||||
import com.cloud.host.Host;
|
||||
import org.apache.cloudstack.storage.command.CopyCmdAnswer;
|
||||
import org.apache.cloudstack.storage.to.SnapshotObjectTO;
|
||||
import org.apache.cloudstack.storage.to.TemplateObjectTO;
|
||||
|
||||
public class MockStorageMotionStrategy implements DataMotionStrategy {
|
||||
|
||||
|
|
@ -45,7 +52,22 @@ public class MockStorageMotionStrategy implements DataMotionStrategy {
|
|||
|
||||
@Override
|
||||
public Void copyAsync(DataObject srcData, DataObject destData, AsyncCompletionCallback<CopyCommandResult> callback) {
|
||||
CopyCommandResult result = new CopyCommandResult("something", null);
|
||||
CopyCmdAnswer answer = null;
|
||||
DataTO data = null;
|
||||
if (destData.getType() == DataObjectType.SNAPSHOT) {
|
||||
SnapshotObjectTO newSnapshot = new SnapshotObjectTO();
|
||||
newSnapshot.setPath(UUID.randomUUID().toString());
|
||||
data = newSnapshot;
|
||||
} else if (destData.getType() == DataObjectType.TEMPLATE) {
|
||||
TemplateObjectTO newTemplate = new TemplateObjectTO();
|
||||
newTemplate.setPath(UUID.randomUUID().toString());
|
||||
newTemplate.setFormat(Storage.ImageFormat.QCOW2);
|
||||
newTemplate.setSize(10L);
|
||||
newTemplate.setPhysicalSize(10L);
|
||||
data = newTemplate;
|
||||
}
|
||||
answer = new CopyCmdAnswer(data);
|
||||
CopyCommandResult result = new CopyCommandResult("something", answer);
|
||||
callback.complete(result);
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import com.cloud.storage.VolumeVO;
|
|||
import com.cloud.storage.dao.SnapshotDao;
|
||||
import com.cloud.storage.dao.VolumeDao;
|
||||
import com.cloud.utils.component.ComponentContext;
|
||||
import com.cloud.utils.db.DB;
|
||||
import junit.framework.Assert;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStore;
|
||||
import org.apache.cloudstack.engine.subsystem.api.storage.DataStoreManager;
|
||||
|
|
@ -61,10 +62,17 @@ import java.net.URISyntaxException;
|
|||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(locations = { "classpath:/fakeDriverTestContext.xml" })
|
||||
public class SnapshotTestWithFakeData {
|
||||
public class SnapshotTestWithFakeData {
|
||||
@Inject
|
||||
SnapshotService snapshotService;
|
||||
@Inject
|
||||
|
|
@ -85,6 +93,7 @@ public class SnapshotTestWithFakeData {
|
|||
VolumeService volumeService;
|
||||
@Inject
|
||||
VolumeDataFactory volumeDataFactory;
|
||||
VolumeInfo vol = null;
|
||||
FakePrimaryDataStoreDriver driver = new FakePrimaryDataStoreDriver();
|
||||
|
||||
@Before
|
||||
|
|
@ -191,4 +200,32 @@ public class SnapshotTestWithFakeData {
|
|||
Assert.assertTrue(result == null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConcurrentSnapshot() throws URISyntaxException, InterruptedException, ExecutionException {
|
||||
DataStore store = createDataStore();
|
||||
FakePrimaryDataStoreDriver dataStoreDriver = (FakePrimaryDataStoreDriver)store.getDriver();
|
||||
dataStoreDriver.makeTakeSnapshotSucceed(true);
|
||||
final VolumeInfo volumeInfo = createVolume(1L, store);
|
||||
Assert.assertTrue(volumeInfo.getState() == Volume.State.Ready);
|
||||
vol = volumeInfo;
|
||||
ExecutorService pool = Executors.newFixedThreadPool(2);
|
||||
boolean result = false;
|
||||
Future<Boolean> future = null;
|
||||
for(int i = 0; i < 1; i++) {
|
||||
future = pool.submit(new Callable<Boolean>() {
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
boolean r = false;
|
||||
try {
|
||||
SnapshotInfo newSnapshot = volumeService.takeSnapshot(vol);
|
||||
Assert.assertTrue(newSnapshot != null);
|
||||
} catch (Exception e) {
|
||||
r = false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
future.get();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,6 @@
|
|||
<bean id="clusterScopeStoragePoolAllocator" class="org.apache.cloudstack.storage.allocator.ClusterScopeStoragePoolAllocator" />
|
||||
<bean id="zoneWideStoragePoolAllocator" class="org.apache.cloudstack.storage.allocator.ZoneWideStoragePoolAllocator" />
|
||||
<bean id="dataStoreProviderManagerImpl" class="org.apache.cloudstack.storage.datastore.provider.DataStoreProviderManagerImpl" />
|
||||
<bean id="ancientDataMotionStrategy" class="org.apache.cloudstack.storage.motion.AncientDataMotionStrategy" />
|
||||
<bean id="storageCacheManagerImpl" class="org.apache.cloudstack.storage.cache.manager.StorageCacheManagerImpl" />
|
||||
<bean id="storageCacheRandomAllocator" class="org.apache.cloudstack.storage.cache.allocator.StorageCacheRandomAllocator" />
|
||||
<bean id="xenserverSnapshotStrategy" class="org.apache.cloudstack.storage.snapshot.XenserverSnapshotStrategy" />
|
||||
|
|
@ -84,4 +83,6 @@
|
|||
<bean id="AccountGuestVlanMapDaoImpl" class="com.cloud.network.dao.AccountGuestVlanMapDaoImpl" />
|
||||
<bean id="StorageCacheReplacementAlgorithm" class="org.apache.cloudstack.storage.cache.manager.StorageCacheReplacementAlgorithmLRU" />
|
||||
<bean id="ServiceOfferingDetailsDao" class="com.cloud.service.dao.ServiceOfferingDetailsDaoImpl" />
|
||||
<bean id='SnapshotManagerImpl' class='com.cloud.storage.snapshot.SnapshotManagerImpl'/>
|
||||
<bean id='SnapshotPolicyDao' class='com.cloud.storage.dao.SnapshotPolicyDaoImpl'/>
|
||||
</beans>
|
||||
|
|
|
|||
|
|
@ -139,8 +139,6 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
|
|||
@Inject
|
||||
protected VMTemplateDao _templateDao;
|
||||
@Inject
|
||||
protected HostDao _hostDao;
|
||||
@Inject
|
||||
protected UserVmDao _vmDao;
|
||||
@Inject
|
||||
protected VolumeDao _volsDao;
|
||||
|
|
@ -157,8 +155,6 @@ public class SnapshotManagerImpl extends ManagerBase implements SnapshotManager,
|
|||
@Inject
|
||||
protected PrimaryDataStoreDao _storagePoolDao;
|
||||
@Inject
|
||||
protected EventDao _eventDao;
|
||||
@Inject
|
||||
protected SnapshotPolicyDao _snapshotPolicyDao = null;
|
||||
@Inject
|
||||
protected SnapshotScheduleDao _snapshotScheduleDao;
|
||||
|
|
|
|||
Loading…
Reference in New Issue