Skip to content

Commit

Permalink
Fix listMonitoredResourceDescriptors tests flakeyness (googleapis#1340)
Browse files Browse the repository at this point in the history
  • Loading branch information
mziccard committed Oct 27, 2016
1 parent bf0fd0c commit f76f1c9
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 37 deletions.
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

0 comments on commit f76f1c9

Please sign in to comment.