-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Redis: Added system test #6375
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
Merged
Redis: Added system test #6375
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
cb6ebdb
Added system test for redis
athakor c779043
Fix review changes
athakor 4480d68
Fix review changes
athakor 98650fc
Fix review changes
athakor b46ce1e
Added -Dredis.network=redis-vpc in continuous as well as nightly inte…
athakor 9672d16
Fix review changes
athakor 8571eee
Fix formatter
athakor 71c9ab0
Fix network full path
athakor a1f48d8
simplify the code
athakor 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
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
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
96 changes: 96 additions & 0 deletions
96
...loud-clients/google-cloud-redis/src/test/java/com/google/cloud/redis/it/ITSystemTest.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,96 @@ | ||
| /* | ||
| * Copyright 2019 Google LLC | ||
| * | ||
| * Licensed 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.google.cloud.redis.it; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import com.google.cloud.ServiceOptions; | ||
| import com.google.cloud.redis.v1beta1.CloudRedisClient; | ||
| import com.google.cloud.redis.v1beta1.Instance; | ||
| import com.google.cloud.redis.v1beta1.InstanceName; | ||
| import com.google.cloud.redis.v1beta1.LocationName; | ||
| import com.google.common.collect.Lists; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
| import java.util.logging.Logger; | ||
| import org.junit.AfterClass; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
|
|
||
| public class ITSystemTest { | ||
|
|
||
| private static CloudRedisClient client; | ||
| private static String projectId; | ||
|
|
||
| private static final Logger log = Logger.getLogger(ITSystemTest.class.getName()); | ||
| private static final Instance.Tier TIER = Instance.Tier.BASIC; | ||
| private static final String INSTANCE_NAME_PREFIX = "test-instance"; | ||
| private static final String INSTANCE = | ||
| INSTANCE_NAME_PREFIX + "-" + UUID.randomUUID().toString().substring(0, 8); | ||
| private static final String LOCATION = "us-central1"; | ||
| private static final int MEMORY_SIZE_GB = 1; | ||
| private static final String AUTHORIZED_NETWORK = System.getProperty("redis.network", "default"); | ||
|
|
||
| @BeforeClass | ||
| public static void beforeClass() throws Exception { | ||
| client = CloudRedisClient.create(); | ||
| projectId = ServiceOptions.getDefaultProjectId(); | ||
|
|
||
| /** Creates a Redis instance based on the specified tier and memory size. */ | ||
| LocationName parent = LocationName.of(projectId, LOCATION); | ||
| String authorizedNetwork = "projects/" + projectId + "/global/networks/" + AUTHORIZED_NETWORK; | ||
| Instance instance = | ||
| Instance.newBuilder() | ||
| .setTier(TIER) | ||
| .setMemorySizeGb(MEMORY_SIZE_GB) | ||
| .setAuthorizedNetwork(authorizedNetwork) | ||
| .build(); | ||
| client.createInstanceAsync(parent, INSTANCE, instance).get(); | ||
| log.info("redis instance created successfully."); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void afterClass() { | ||
|
|
||
| /** Deletes a specific Redis instance. Instance stops serving and data is deleted. */ | ||
| InstanceName name = InstanceName.of(projectId, LOCATION, INSTANCE); | ||
| client.deleteInstanceAsync(name); | ||
| log.info("redis instance deleted successfully."); | ||
| client.close(); | ||
| } | ||
|
|
||
| @Test | ||
| public void testGetInstance() { | ||
| InstanceName name = InstanceName.of(projectId, LOCATION, INSTANCE); | ||
| Instance response = client.getInstance(name); | ||
| assertEquals(TIER, response.getTier()); | ||
| assertEquals(MEMORY_SIZE_GB, response.getMemorySizeGb()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testListInstance() { | ||
| LocationName parent = LocationName.of(projectId, LOCATION); | ||
| CloudRedisClient.ListInstancesPagedResponse pagedListResponse = client.listInstances(parent); | ||
| List<Instance> resources = Lists.newArrayList(pagedListResponse.iterateAll()); | ||
| int instance = 0, count = 0; | ||
| while (instance < resources.size()) { | ||
| count++; | ||
| instance++; | ||
| } | ||
| assertEquals(count, resources.size()); | ||
| } | ||
| } | ||
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.
This is failing with an invalid config:
Invalid authorized network 'default'. Legacy networks are not supported.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.
@chingor13 Its working for grass-clump-project locally, from console as well as api explorer. Does it need any setting on project thats used for CI? Otherwise we will have to create VPC run system test and delete VPC which would add dependency on compute client.
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.
This is likely because our test project is very old and has some older grandfathered in settings (like default networking) still configured. I'll investigate some more.
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.
I'm hesitant to change the default network for the test project, so I created a new
redis-vpcnetwork in our test project. Let's make the test configurable (via a maven param like-Dredis.network=redis-vpcwhich we can add here (and in the continuous integration config). We can default that value todefaultfor most other users who run the tests.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.
sounds good. Thanks @chingor13