Skip to content

Fix listMonitoredResourceDescriptors tests flakeyness #1340

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 1 commit into from
Oct 27, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import com.google.cloud.logging.Metric;
import com.google.cloud.logging.Sink;
import com.google.cloud.logging.testing.RemoteLoggingHelper;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators;
import com.google.common.collect.Sets;

Expand All @@ -36,20 +35,13 @@
import org.junit.rules.ExpectedException;
import org.junit.rules.Timeout;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ExecutionException;

public class ITLoggingSnippets {

private static final String DATASET = "dataset";
private static final Set<String> DESCRIPTOR_TYPES = ImmutableSet.of("gce_instance", "gae_app",
"cloudsql_database", "api", "gcs_bucket", "global", "dataflow_step", "build",
"app_script_function", "dataproc_cluster", "ml_job", "bigquery_resource", "container",
"gke_cluster", "cloud_debugger_resource", "http_load_balancer", "aws_ec2_instance",
"client_auth_config_brand", "client_auth_config_client", "logging_log", "logging_sink",
"metric", "project", "testservice_matrix", "service_account", "deployment");

private static Logging logging;
private static LoggingSnippets loggingSnippets;
Expand Down Expand Up @@ -134,21 +126,19 @@ public void testMetric() throws ExecutionException, InterruptedException {
public void testMonitoredResourceDescriptor() throws ExecutionException, InterruptedException {
Iterator<MonitoredResourceDescriptor> iterator =
loggingSnippets.listMonitoredResourceDescriptors().iterateAll();
Set<String> descriptorTypes = new HashSet<>();
int count = 0;
while (iterator.hasNext()) {
descriptorTypes.add(iterator.next().type());
}
for (String type : DESCRIPTOR_TYPES) {
assertTrue(descriptorTypes.contains(type));
assertNotNull(iterator.next().getType());
count += 1;
}
assertTrue(count > 0);
iterator = loggingSnippets.listMonitoredResourceDescriptorsAsync().iterateAll();
descriptorTypes.clear();
count = 0;
while (iterator.hasNext()) {
descriptorTypes.add(iterator.next().type());
}
for (String type : DESCRIPTOR_TYPES) {
assertTrue(descriptorTypes.contains(type));
assertNotNull(iterator.next().getType());
count += 1;
}
assertTrue(count > 0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
import com.google.cloud.logging.SinkInfo.Destination.DatasetDestination;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators;
import com.google.common.collect.Sets;
import com.google.protobuf.Any;
Expand All @@ -47,7 +46,6 @@
import org.junit.rules.ExpectedException;
import org.junit.rules.Timeout;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.ExecutionException;
Expand All @@ -60,13 +58,6 @@
*/
public abstract class BaseSystemTest {

private static final Set<String> DESCRIPTOR_TYPES = ImmutableSet.of("gce_instance", "gae_app",
"cloudsql_database", "api", "gcs_bucket", "global", "dataflow_step", "build",
"app_script_function", "dataproc_cluster", "ml_job", "bigquery_resource", "container",
"gke_cluster", "cloud_debugger_resource", "http_load_balancer", "aws_ec2_instance",
"client_auth_config_brand", "client_auth_config_client", "logging_log", "logging_sink",
"metric", "project", "testservice_matrix", "service_account", "deployment");

@Rule
public ExpectedException thrown = ExpectedException.none();

Expand Down Expand Up @@ -214,27 +205,25 @@ public void testListSinksAsync() throws ExecutionException, InterruptedException
public void testListMonitoredResourceDescriptors() {
Iterator<MonitoredResourceDescriptor> iterator =
logging().listMonitoredResourceDescriptors(Logging.ListOption.pageSize(1)).iterateAll();
Set<String> descriptorTypes = new HashSet<>();
int count = 0;
while (iterator.hasNext()) {
descriptorTypes.add(iterator.next().getType());
}
for (String type : DESCRIPTOR_TYPES) {
assertTrue(descriptorTypes.contains(type));
assertNotNull(iterator.next().getType());
count += 1;
}
assertTrue(count > 0);
}

@Test
public void testListMonitoredResourceDescriptorsAsync()
throws ExecutionException, InterruptedException {
Iterator<MonitoredResourceDescriptor> iterator = logging()
.listMonitoredResourceDescriptorsAsync(Logging.ListOption.pageSize(1)).get().iterateAll();
Set<String> descriptorTypes = new HashSet<>();
int count = 0;
while (iterator.hasNext()) {
descriptorTypes.add(iterator.next().getType());
}
for (String type : DESCRIPTOR_TYPES) {
assertTrue(descriptorTypes.contains(type));
assertNotNull(iterator.next().getType());
count += 1;
}
assertTrue(count > 0);
}

@Test
Expand Down