-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[#5919] Platform: change default storage option for AWS provider to 1x250GB #6792
Changes from all commits
1f79e0c
bc1a948
2a02efb
8e3e7ff
4922831
bd16e96
d761c16
1a54cfa
8202218
b8bc59e
b98f2cc
fd70c2d
0300b33
ad53844
8093bb6
afac6f2
da5d7a2
f9895eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.hamcrest.core.AllOf.allOf; | ||
import static org.junit.Assert.*; | ||
import static org.mockito.Mockito.when; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
@@ -15,20 +16,28 @@ | |
|
||
import com.fasterxml.jackson.databind.JsonNode; | ||
import com.fasterxml.jackson.databind.node.ObjectNode; | ||
import com.typesafe.config.Config; | ||
import com.yugabyte.yw.common.ModelFactory; | ||
import com.yugabyte.yw.models.InstanceType.VolumeType; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import com.yugabyte.yw.common.FakeDBApplication; | ||
import play.libs.Json; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class InstanceTypeTest extends FakeDBApplication { | ||
private Provider defaultProvider; | ||
private Customer defaultCustomer; | ||
private InstanceType.InstanceTypeDetails defaultDetails; | ||
|
||
@Mock | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. where is a test where you have to setup this mock? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah! Didn't realise this is for entity class. We can't mock config in this file. Most of the values are being read from in memory. Thanks! |
||
Config mockConfig; | ||
|
||
@Before | ||
public void setUp() { | ||
defaultCustomer = ModelFactory.testCustomer(); | ||
|
@@ -48,7 +57,7 @@ public void testCreate() { | |
assertEquals("aws", i1.getProviderCode()); | ||
assertEquals("foo", i1.getInstanceTypeCode()); | ||
} | ||
|
||
@Test | ||
public void testGetNonDefaultInstanceTypeDetails() { | ||
int volumeCount = 3; | ||
|
@@ -64,7 +73,7 @@ public void testGetNonDefaultInstanceTypeDetails() { | |
assertEquals(String.format("/mnt/d%d", i), v.mountPath); | ||
} | ||
} | ||
|
||
@Test | ||
public void testGetDefaultInstanceTypeDetails() { | ||
InstanceType.InstanceTypeDetails itDetails = | ||
|
@@ -90,7 +99,7 @@ public void testFindByProvider() { | |
instanceType.setActive(false); | ||
instanceType.save(); | ||
InstanceType.upsert(newProvider.code, "bar", 2, 10.0, defaultDetails); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is incorrect. Not sure what is your confusion.
Hope it helps. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to refactor the code lil bit. Forgot to apply @RunWith(MockitoJUnitRunner.class) on top to use mock otherwise we will get null. Now its working fine. I really learnt a lot while working on this change. Please let me know if you still think, some changes are required. Thanks for all your suggestions:) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 for right attitude! |
||
List<InstanceType> instanceTypeList = InstanceType.findByProvider(defaultProvider); | ||
List<InstanceType> instanceTypeList = InstanceType.findByProvider(defaultProvider, mockConfig); | ||
assertNotNull(instanceTypeList); | ||
assertEquals(2, instanceTypeList.size()); | ||
Set<String> possibleTypes = new HashSet<>(); | ||
|
@@ -105,19 +114,41 @@ public void testFindByProvider() { | |
public void testFindByProviderWithUnSupportedInstances() { | ||
InstanceType.upsert(defaultProvider.code, "t2.medium", 3, 10.0, defaultDetails); | ||
InstanceType.upsert(defaultProvider.code, "c3.medium", 2, 10.0, defaultDetails); | ||
List<InstanceType> instanceTypeList = InstanceType.findByProvider(defaultProvider); | ||
List<InstanceType> instanceTypeList = InstanceType.findByProvider(defaultProvider, mockConfig); | ||
assertNotNull(instanceTypeList); | ||
assertEquals(1, instanceTypeList.size()); | ||
assertThat(instanceTypeList.get(0).getInstanceTypeCode(), | ||
allOf(notNullValue(), equalTo("c3.medium"))); | ||
} | ||
|
||
|
||
@Test | ||
public void testFindByProviderWithEmptyInstanceTypeDetails() { | ||
InstanceType.upsert(defaultProvider.code, "c5.medium", 3, 10.0, | ||
new InstanceType.InstanceTypeDetails()); | ||
when(mockConfig.getInt(InstanceType.YB_AWS_DEFAULT_VOLUME_COUNT_KEY)) | ||
.thenReturn(1); | ||
when(mockConfig.getInt(InstanceType.YB_AWS_DEFAULT_VOLUME_SIZE_GB_KEY)) | ||
.thenReturn(250); | ||
List<InstanceType> instanceTypeList = InstanceType.findByProvider(defaultProvider, mockConfig); | ||
assertNotNull(instanceTypeList); | ||
InstanceType.VolumeDetails volumeDetails = instanceTypeList | ||
.get(0) | ||
.instanceTypeDetails | ||
.volumeDetailsList | ||
.get(0); | ||
assertEquals(250, volumeDetails.volumeSizeGB.intValue()); | ||
assertEquals(InstanceType.VolumeType.EBS, volumeDetails.volumeType); | ||
assertEquals(String.format("/mnt/d%d", 0), volumeDetails.mountPath); | ||
assertThat(instanceTypeList.get(0).getInstanceTypeDetails().getVolumeDetailsList().size(), | ||
allOf(notNullValue(), equalTo(1))); | ||
} | ||
|
||
@Test | ||
public void testDeleteByProvider() { | ||
Provider newProvider = ModelFactory.gcpProvider(defaultCustomer); | ||
InstanceType.upsert(newProvider.code, "bar", 2, 10.0, defaultDetails); | ||
InstanceType.deleteInstanceTypesForProvider(newProvider); | ||
List<InstanceType> instanceTypeList = InstanceType.findByProvider(newProvider); | ||
InstanceType.deleteInstanceTypesForProvider(newProvider, mockConfig); | ||
List<InstanceType> instanceTypeList = InstanceType.findByProvider(newProvider, mockConfig); | ||
assertEquals(0, instanceTypeList.size()); | ||
} | ||
|
||
|
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.
Do not mix ctor injections and field injections in same class.
Either fix all existing fields to be parameters here or make the new field use field injection.
FWIW, using ctor injection with private fina fields is the best practice. But i ll leave it to you which option you want for now.
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.
Done. Thanks!