-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Issue 2774: Changed the implementation of isVolumeOnManagedStorage(VolumeInfo) to… #2776
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mike-tutkowski
merged 1 commit into
apache:4.11
from
mike-tutkowski:vol-on-managed-storage
Aug 10, 2018
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
...motion/test/org/apache/cloudstack/storage/motion/StorageSystemDataMotionStrategyTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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.cloudstack.storage.motion; | ||
|
|
||
| import com.cloud.storage.DataStoreRole; | ||
| import com.cloud.storage.ImageStore; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataMotionStrategy; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataObject; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.DataStore; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.PrimaryDataStore; | ||
| import org.apache.cloudstack.engine.subsystem.api.storage.StrategyPriority; | ||
| import org.apache.cloudstack.storage.datastore.PrimaryDataStoreImpl; | ||
| import org.apache.cloudstack.storage.datastore.db.PrimaryDataStoreDao; | ||
| import org.apache.cloudstack.storage.datastore.db.StoragePoolVO; | ||
| import org.apache.cloudstack.storage.image.store.ImageStoreImpl; | ||
| import org.apache.cloudstack.storage.volume.VolumeObject; | ||
| import org.junit.Before; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
| import org.mockito.InjectMocks; | ||
| import org.mockito.Mock; | ||
| import org.mockito.runners.MockitoJUnitRunner; | ||
|
|
||
| import static org.junit.Assert.assertTrue; | ||
| import static org.mockito.Mockito.doReturn; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.MockitoAnnotations.initMocks; | ||
|
|
||
| @RunWith(MockitoJUnitRunner.class) | ||
| public class StorageSystemDataMotionStrategyTest { | ||
|
|
||
| @Mock | ||
| VolumeObject source; | ||
| @Mock | ||
| DataObject destination; | ||
| @Mock | ||
| PrimaryDataStore sourceStore; | ||
| @Mock | ||
| ImageStore destinationStore; | ||
|
|
||
| @InjectMocks | ||
| DataMotionStrategy strategy = new StorageSystemDataMotionStrategy(); | ||
| @Mock | ||
| PrimaryDataStoreDao _storagePoolDao; | ||
|
|
||
| @Before public void setUp() throws Exception { | ||
| sourceStore = mock(PrimaryDataStoreImpl.class); | ||
| destinationStore = mock(ImageStoreImpl.class); | ||
| source = mock(VolumeObject.class); | ||
| destination = mock(VolumeObject.class); | ||
|
|
||
| initMocks(strategy); | ||
| } | ||
|
|
||
| @Test | ||
| public void cantHandleSecondary() { | ||
| doReturn(sourceStore).when(source).getDataStore(); | ||
| doReturn(DataStoreRole.Primary).when(sourceStore).getRole(); | ||
| doReturn(destinationStore).when(destination).getDataStore(); | ||
| doReturn(DataStoreRole.Image).when((DataStore)destinationStore).getRole(); | ||
| doReturn(sourceStore).when(source).getDataStore(); | ||
| doReturn(destinationStore).when(destination).getDataStore(); | ||
| StoragePoolVO storeVO = new StoragePoolVO(); | ||
| doReturn(storeVO).when(_storagePoolDao).findById(0l); | ||
|
|
||
| assertTrue(strategy.canHandle(source,destination) == StrategyPriority.CANT_HANDLE); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about a unit test here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@DaanHoogland is planning on writing a unit test for the higher-level canHandle method (to add to this PR).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, I am. I am struggling with the large number of injects but I think the canHandle() should be tested indeed, as the error was because the strategy returned a wrong priority from that call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is why we should unit test methods instead. We need to reduce the test code. Otherwise it becomes almost impossible to maintain them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, I'm missing your point
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mike-tutkowski are you going to add some unit test(s)? this is ready for merging otherwise.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rhtyd I believe @rafaelweingartner noted (perhaps on the mailing list) that he would like to add one unit test to this PR before it is merged. Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I think @DaanHoogland was planning on adding a unit test, as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mike-tutkowski Daan has already sent a PR to add unit test to your branch, can you merge that. See mike-tutkowski#6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mike-tutkowski the PR I said I wanted to create some unit tests is not this one, it is the other one I worked.