@Test public void testNoHosts() throws Exception { assertEquals(ImmutableSet.of(), getGroupMonitor().get()); startGroupMonitor(); assertEquals(ImmutableSet.of(), getGroupMonitor().get()); }
@Test public void testListTypesByFilter() throws Exception { AttributeDefinition attr = TypesUtil.createOptionalAttrDef("attr", DataTypes.STRING_TYPE); String a = createType( TypesSerialization.toJson( TypesUtil.createClassTypeDef( "A" + randomString(), ImmutableSet.<String>of(), attr), false)) .get(0); String a1 = createType( TypesSerialization.toJson( TypesUtil.createClassTypeDef("A1" + randomString(), ImmutableSet.of(a), attr), false)) .get(0); String b = createType( TypesSerialization.toJson( TypesUtil.createClassTypeDef( "B" + randomString(), ImmutableSet.<String>of(), attr), false)) .get(0); String c = createType( TypesSerialization.toJson( TypesUtil.createClassTypeDef("C" + randomString(), ImmutableSet.of(a, b), attr), false)) .get(0); List<String> results = serviceClient.listTypes(DataTypes.TypeCategory.CLASS, a, b); assertEquals(results, Arrays.asList(a1), "Results: " + results); }
@SuppressWarnings("unchecked") @Test public void testGetAggregatorStepsWithParDoBoundMultiExtractsSteps() { @SuppressWarnings("rawtypes") ParDo.BoundMulti bound = mock(ParDo.BoundMulti.class, "BoundMulti"); AggregatorProvidingDoFn<Object, Void> fn = new AggregatorProvidingDoFn<>(); when(bound.getFn()).thenReturn(fn); Aggregator<Long, Long> aggregatorOne = fn.addAggregator(new Max.MaxLongFn()); Aggregator<Double, Double> aggregatorTwo = fn.addAggregator(new Min.MinDoubleFn()); TransformTreeNode transformNode = mock(TransformTreeNode.class); when(transformNode.getTransform()).thenReturn(bound); doAnswer(new VisitNodesAnswer(ImmutableList.of(transformNode))) .when(p) .traverseTopologically(Mockito.any(PipelineVisitor.class)); AggregatorPipelineExtractor extractor = new AggregatorPipelineExtractor(p); Map<Aggregator<?, ?>, Collection<PTransform<?, ?>>> aggregatorSteps = extractor.getAggregatorSteps(); assertEquals(ImmutableSet.<PTransform<?, ?>>of(bound), aggregatorSteps.get(aggregatorOne)); assertEquals(ImmutableSet.<PTransform<?, ?>>of(bound), aggregatorSteps.get(aggregatorTwo)); assertEquals(2, aggregatorSteps.size()); }
/** * Used source from jclouds project. {@link * org.jclouds.ec2.compute.EC2TemplateBuilderTest#newTemplateBuilder} */ @SuppressWarnings("unchecked") protected TemplateBuilder newTemplateBuilder( Supplier<Set<? extends Image>> images, Supplier<LoadingCache<RegionAndName, ? extends Image>> imageCache) { Provider<TemplateOptions> optionsProvider = mock(Provider.class); Provider<TemplateBuilder> templateBuilderProvider = mock(Provider.class); TemplateOptions defaultOptions = mock(TemplateOptions.class); GetImageStrategy getImageStrategy = mock(GetImageStrategy.class); when(optionsProvider.get()).thenReturn(defaultOptions); Supplier<Set<? extends Location>> locations = Suppliers.<Set<? extends Location>>ofInstance(ImmutableSet.of(jcloudsDomainLocation)); Supplier<Set<? extends Hardware>> sizes = Suppliers.<Set<? extends Hardware>>ofInstance(ImmutableSet.of(HARDWARE_SUPPORTING_BOGUS)); return new EC2TemplateBuilderImpl( locations, new ImageCacheSupplier(images, 60), sizes, Suppliers.ofInstance(jcloudsDomainLocation), optionsProvider, templateBuilderProvider, getImageStrategy, imageCache) { @Override protected ToStringHelper string() { return super.string().add("type", "Stubbed-TemplateBuilder"); } }; }
@Override public <T> Set<T> eval( QueryEnvironment<T> env, ImmutableList<Argument> args, ListeningExecutorService executor) throws QueryException, InterruptedException { QueryExpression argument = args.get(args.size() - 1).getExpression(); String attr = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, args.get(0).getWord()); final String attrValue = args.get(1).getWord(); final Predicate<Object> predicate = new Predicate<Object>() { @Override public boolean apply(Object input) { return attrValue.equals(input.toString()); } }; Set<T> result = new LinkedHashSet<>(); for (T target : argument.eval(env, executor)) { ImmutableSet<Object> matchingObjects = env.filterAttributeContents(target, attr, predicate); if (!matchingObjects.isEmpty()) { result.add(target); } } return result; }
@Test public void testShowSchemasFromOther() throws Exception { MaterializedResult result = computeActual("SHOW SCHEMAS FROM tpch"); ImmutableSet<String> schemaNames = ImmutableSet.copyOf(transform(result.getMaterializedRows(), onlyColumnGetter())); assertTrue(schemaNames.containsAll(ImmutableSet.of(INFORMATION_SCHEMA, "sys", "tiny"))); }
/** * Creates a new environment. * * @param configuration the service's {@link Configuration} * @param service the service */ public Environment(Configuration configuration, AbstractService<?> service) { this.service = service; this.config = new DropwizardResourceConfig() { @Override public void validate() { super.validate(); logResources(); logProviders(); logHealthChecks(); logManagedObjects(); logEndpoints(); } }; this.healthChecks = ImmutableSet.builder(); this.servlets = ImmutableMap.builder(); this.filters = ImmutableMultimap.builder(); this.servletListeners = ImmutableSet.builder(); this.tasks = ImmutableSet.builder(); this.lifeCycle = new AggregateLifeCycle(); final HttpServlet jerseyContainer = service.getJerseyContainer(config); if (jerseyContainer != null) { addServlet(jerseyContainer, configuration.getHttpConfiguration().getRootPath()) .setInitOrder(Integer.MAX_VALUE); } addTask(new GarbageCollectionTask()); }
public ResponseLinking copyWithFilteredResponses(final Predicate<Response> toKeepCondition) { final Set<Response> newIncompletes = Sets.filter(incompleteResponses(), toKeepCondition); final ImmutableSet.Builder<ResponseSet> newResponseSetsB = ImmutableSet.builder(); final ImmutableBiMap.Builder<String, ResponseSet> responseSetsIdB = ImmutableBiMap.builder(); // to account for ResponseSets merging due to lost annotation final Set<ResponseSet> alreadyAdded = Sets.newHashSet(); for (final ResponseSet responseSet : responseSets()) { final ImmutableSet<Response> okResponses = FluentIterable.from(responseSet.asSet()).filter(toKeepCondition).toSet(); if (!okResponses.isEmpty()) { final ResponseSet newResponseSet = ResponseSet.from(okResponses); if (alreadyAdded.contains(newResponseSet)) { continue; } alreadyAdded.add(newResponseSet); newResponseSetsB.add(newResponseSet); if (responseSetIds().isPresent()) { responseSetsIdB.put(responseSetIds().get().inverse().get(responseSet), newResponseSet); } } } final ImmutableSet<ResponseSet> newResponseSets = newResponseSetsB.build(); final ResponseLinking.Builder ret = ResponseLinking.builder() .docID(docID()) .responseSets(newResponseSets) .incompleteResponses(newIncompletes); if (responseSetIds().isPresent()) { ret.responseSetIds(responseSetsIdB.build()); } return ret.build(); }
@Value.Check protected void checkValidity() { // no incomplete response may appear in any response set final ImmutableSet<Response> allResponsesInSets = ImmutableSet.copyOf(concat(responseSets())); for (final Response incompleteResponse : incompleteResponses()) { checkArgument( !allResponsesInSets.contains(incompleteResponse), "A response may not be both completed and incomplete"); } if (responseSetIds().isPresent()) { for (final String id : responseSetIds().get().keySet()) { checkArgument(!id.contains("-"), "Event frame IDs may not contain -s"); checkArgument(!id.contains("\t"), "Event frame IDs may not contain tabs"); } // we can have an empty output file, verify that all the responseSets have an id checkArgument( responseSets().size() == responseSetIds().get().size(), "Response set IDs are missing"); checkArgument( responseSetIds().get().keySet().size() == responseSets().size(), "All response set IDs must be unique"); CollectionUtils.assertSameElementsOrIllegalArgument( responseSets(), responseSetIds().get().values(), "Response sets did not match IDs", "Response sets in list", "Response sets in ID map"); } }
@Value.Lazy public List<TypeElement> includedTypes() { Optional<IncludeMirror> includes = include(); ImmutableList<TypeMirror> typeMirrors = includes.isPresent() ? ImmutableList.copyOf(includes.get().valueMirror()) : ImmutableList.<TypeMirror>of(); FluentIterable<TypeElement> typeElements = FluentIterable.from(typeMirrors) .filter(DeclaredType.class) .transform(DeclatedTypeToElement.FUNCTION); ImmutableSet<String> uniqueTypeNames = typeElements.filter(IsPublic.PREDICATE).transform(ElementToName.FUNCTION).toSet(); if (uniqueTypeNames.size() != typeMirrors.size()) { report() .annotationNamed(IncludeMirror.simpleName()) .warning( "Some types were ignored, non-supported for inclusion: duplicates, non declared reference types, non-public"); } return typeElements.toList(); }
private ImmutableSet<String> prepareDirectory( String dirname, Pattern filePattern, ImmutableSet<String> requiredHashes) throws Exception { try (TraceEventLogger ignored = TraceEventLogger.start(eventBus, "prepare_" + dirname)) { String dirPath = dataRoot.resolve(dirname).toString(); mkDirP(dirPath); String output = AdbHelper.executeCommandWithErrorChecking(device, "ls " + dirPath); ImmutableSet.Builder<String> foundHashes = ImmutableSet.builder(); ImmutableSet.Builder<String> filesToDelete = ImmutableSet.builder(); processLsOutput(output, filePattern, requiredHashes, foundHashes, filesToDelete); String commandPrefix = "cd " + dirPath + " && rm "; // Add a fudge factor for separators and error checking. final int overhead = commandPrefix.length() + 100; for (List<String> rmArgs : chunkArgs(filesToDelete.build(), MAX_ADB_COMMAND_SIZE - overhead)) { String command = commandPrefix + Joiner.on(' ').join(rmArgs); LOG.debug("Executing %s", command); AdbHelper.executeCommandWithErrorChecking(device, command); } return foundHashes.build(); } }
@Test public void testLibraryHeaderGroups() throws NoSuchBuildTargetException { NewNativeTargetProjectMutator mutator = mutatorWithCommonDefaults(); SourcePath foo = new FakeSourcePath("HeaderGroup1/foo.h"); SourcePath bar = new FakeSourcePath("HeaderGroup1/bar.h"); SourcePath baz = new FakeSourcePath("HeaderGroup2/baz.h"); mutator.setPublicHeaders(ImmutableSet.of(bar, baz)); mutator.setPrivateHeaders(ImmutableSet.of(foo)); NewNativeTargetProjectMutator.Result result = mutator.buildTargetAndAddToProject(generatedProject); PBXGroup sourcesGroup = result.targetGroup.getOrCreateChildGroupByName("Sources"); assertThat(sourcesGroup.getChildren(), hasSize(2)); PBXGroup group1 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 0); assertEquals("HeaderGroup1", group1.getName()); assertThat(group1.getChildren(), hasSize(2)); PBXFileReference fileRefBar = (PBXFileReference) Iterables.get(group1.getChildren(), 0); assertEquals("bar.h", fileRefBar.getName()); PBXFileReference fileRefFoo = (PBXFileReference) Iterables.get(group1.getChildren(), 1); assertEquals("foo.h", fileRefFoo.getName()); PBXGroup group2 = (PBXGroup) Iterables.get(sourcesGroup.getChildren(), 1); assertEquals("HeaderGroup2", group2.getName()); assertThat(group2.getChildren(), hasSize(1)); PBXFileReference fileRefBaz = (PBXFileReference) Iterables.get(group2.getChildren(), 0); assertEquals("baz.h", fileRefBaz.getName()); }
/** * In devstack and going forward, namespaces are being deprecated. When namespace is missing (or * replaced with a "fake" /fake namespace), allow matching by name and alias. */ public void testPresentWhenNameSpaceIsFakeAndMatchByNameOrAlias() throws SecurityException, NoSuchMethodException { // Revert to alias Extension floatingIpsWithFakeNamespace = floatingIps.toBuilder().namespace(URI.create("http://docs.openstack.org/ext/fake")).build(); // Revert to name Extension floatingIpsWithFakeNamespaceAndAlias = floatingIps .toBuilder() .namespace(URI.create("http://docs.openstack.org/ext/fake")) .alias("fake") .build(); Multimap<URI, URI> aliases = ImmutableMultimap.of(); assertEquals( whenExtensionsAndAliasesInRegionInclude( "region", ImmutableSet.of(floatingIpsWithFakeNamespace), aliases) .apply(getFloatingIPExtension(ImmutableList.<Object>of("region"))), Optional.of("foo")); assertEquals( whenExtensionsAndAliasesInRegionInclude( "region", ImmutableSet.of(floatingIpsWithFakeNamespaceAndAlias), aliases) .apply(getFloatingIPExtension(ImmutableList.<Object>of("region"))), Optional.of("foo")); }
/** * Construct {@link TemporaryPath}. * * @param confKeys {@link Configuration} keys containing directories to override */ public TemporaryPath(String... confKeys) { if (confKeys != null) { this.confKeys = ImmutableSet.copyOf(confKeys); } else { this.confKeys = ImmutableSet.of(); } }
@VisibleForTesting // productionVisibility = Visibility.PRIVATE public CppCompilationContext build(ActionOwner owner, MiddlemanFactory middlemanFactory) { // We don't create middlemen in LIPO collector subtree, because some target CT // will do that instead. Artifact prerequisiteStampFile = (ruleContext != null && ruleContext.getFragment(CppConfiguration.class).isLipoContextCollector()) ? getMiddlemanArtifact(middlemanFactory) : createMiddleman(owner, middlemanFactory); return new CppCompilationContext( new CommandLineContext( ImmutableList.copyOf(includeDirs), ImmutableList.copyOf(quoteIncludeDirs), ImmutableList.copyOf(systemIncludeDirs), ImmutableList.copyOf(defines)), prerequisiteStampFile == null ? ImmutableSet.<Artifact>of() : ImmutableSet.of(prerequisiteStampFile), declaredIncludeDirs.build(), declaredIncludeWarnDirs.build(), declaredIncludeSrcs.build(), pregreppedHdrs.build(), moduleInfo.build(), picModuleInfo.build(), transitiveModuleMaps.build(), directModuleMaps.build(), cppModuleMap, provideTransitiveModuleMaps, useHeaderModules); }
@Override public List<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) throws IOException { ImmutableList.Builder<Step> commands = ImmutableList.builder(); String outputDirectory = getOutputDirectory(); Step mkdir = new MkdirStep(outputDirectory); commands.add(mkdir); ImmutableSet<String> includePaths; if (metaInfDirectory != null) { String stagingRoot = outputDirectory + "/meta_inf_staging"; String stagingTarget = stagingRoot + "/META-INF"; MakeCleanDirectoryStep createStagingRoot = new MakeCleanDirectoryStep(stagingRoot); commands.add(createStagingRoot); MkdirAndSymlinkFileStep link = new MkdirAndSymlinkFileStep(metaInfDirectory, stagingTarget); commands.add(link); includePaths = ImmutableSet.<String>builder() .add(stagingRoot) .addAll(getTransitiveClasspathEntries().values()) .build(); } else { includePaths = ImmutableSet.copyOf(getTransitiveClasspathEntries().values()); } String outputFile = getOutputFile(); Step jar = new JarDirectoryStep(outputFile, includePaths, mainClass, manifestFile); commands.add(jar); return commands.build(); }
@Test public void testGetJobUpdateDiffWithUpdateRemove() throws Exception { TaskConfig task1 = defaultTask(false).setNumCpus(1.0); TaskConfig task2 = defaultTask(false).setNumCpus(2.0); TaskConfig task3 = defaultTask(false).setNumCpus(3.0); ImmutableSet.Builder<IScheduledTask> tasks = ImmutableSet.builder(); makeTasks(0, 10, task1, tasks); makeTasks(10, 20, task2, tasks); makeTasks(20, 30, task3, tasks); expect(storageUtil.jobStore.fetchJob(JOB_KEY)).andReturn(Optional.absent()); storageUtil.expectTaskFetch(Query.jobScoped(JOB_KEY).active(), tasks.build()); control.replay(); JobUpdateRequest request = new JobUpdateRequest() .setTaskConfig(defaultTask(false).setNumCpus(6.0)) .setInstanceCount(20) .setSettings(new JobUpdateSettings()); GetJobUpdateDiffResult expected = new GetJobUpdateDiffResult() .setRemove(ImmutableSet.of(group(task3, new Range(20, 29)))) .setUpdate( ImmutableSet.of(group(task1, new Range(0, 9)), group(task2, new Range(10, 19)))) .setAdd(ImmutableSet.of()) .setUnchanged(ImmutableSet.of()); Response response = assertOkResponse(thrift.getJobUpdateDiff(request)); assertEquals(expected, response.getResult().getGetJobUpdateDiffResult()); }
/** * Returns the configurable attribute conditions necessary to evaluate the given configured * target, or null if not all dependencies have yet been SkyFrame-evaluated. */ @Nullable private Set<ConfigMatchingProvider> getConfigurableAttributeConditions( TargetAndConfiguration ctg, Environment env) { if (!(ctg.getTarget() instanceof Rule)) { return ImmutableSet.of(); } Rule rule = (Rule) ctg.getTarget(); RawAttributeMapper mapper = RawAttributeMapper.of(rule); Set<SkyKey> depKeys = new LinkedHashSet<>(); for (Attribute attribute : rule.getAttributes()) { for (Label label : mapper.getConfigurabilityKeys(attribute.getName(), attribute.getType())) { if (!BuildType.Selector.isReservedLabel(label)) { depKeys.add(ConfiguredTargetValue.key(label, ctg.getConfiguration())); } } } Map<SkyKey, SkyValue> cts = env.getValues(depKeys); if (env.valuesMissing()) { return null; } ImmutableSet.Builder<ConfigMatchingProvider> conditions = ImmutableSet.builder(); for (SkyValue ctValue : cts.values()) { ConfiguredTarget ct = ((ConfiguredTargetValue) ctValue).getConfiguredTarget(); conditions.add(Preconditions.checkNotNull(ct.getProvider(ConfigMatchingProvider.class))); } return conditions.build(); }
/** * Helper to add srcs and deps Soy files to a SoyFileSet builder. Also does sanity checks. * * @param sfsBuilder The SoyFileSet builder to add to. * @param inputPrefix The input path prefix to prepend to all the file paths. * @param srcs The srcs from the --srcs flag. Exactly one of 'srcs' and 'args' must be nonempty. * @param args The old-style srcs from the command line (that's how they were specified before we * added the --srcs flag). Exactly one of 'srcs' and 'args' must be nonempty. * @param deps The deps from the --deps flag, or empty list if not applicable. * @param exitWithErrorFn A function that exits with an error message followed by a usage message. */ static void addSoyFilesToBuilder( Builder sfsBuilder, String inputPrefix, Collection<String> srcs, Collection<String> args, Collection<String> deps, Collection<String> indirectDeps, Function<String, Void> exitWithErrorFn) { if (srcs.isEmpty() && args.isEmpty()) { exitWithErrorFn.apply("Must provide list of source Soy files (--srcs)."); } if (!srcs.isEmpty() && !args.isEmpty()) { exitWithErrorFn.apply( "Found source Soy files from --srcs and from args (please use --srcs only)."); } // Create Set versions of each of the arguments, and de-dupe. If something is included as // multiple file kinds, we'll keep the strongest one; a file in both srcs and deps will be a // src, and one in both deps and indirect_deps will be a dep. // TODO(gboyer): Maybe stop supporting old style (srcs from command line args) at some point. Set<String> srcsSet = ImmutableSet.<String>builder().addAll(srcs).addAll(args).build(); Set<String> depsSet = Sets.difference(ImmutableSet.copyOf(deps), srcsSet); Set<String> indirectDepsSet = Sets.difference(ImmutableSet.copyOf(indirectDeps), Sets.union(srcsSet, depsSet)); for (String src : srcsSet) { sfsBuilder.addWithKind(new File(inputPrefix + src), SoyFileKind.SRC); } for (String dep : depsSet) { sfsBuilder.addWithKind(new File(inputPrefix + dep), SoyFileKind.DEP); } for (String dep : indirectDepsSet) { sfsBuilder.addWithKind(new File(inputPrefix + dep), SoyFileKind.INDIRECT_DEP); } }
@Test public void testFetchContentWithMarker() throws Exception { oauth.httpResponse = CACHEABLE; // First entry added to cache is unmarked HttpResponse httpResponse = requestPipeline.execute(signedRequest); assertEquals(CACHEABLE, httpResponse); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidate content for OwnerX. Next entry will have owner mark service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1").create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT1", httpResponse.getResponseAsString()); assertEquals("o=1;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidate content for ViewerX. Next entry will have both owner and viewer mark service.invalidateUserResources(ImmutableSet.of("ViewerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT2").create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT2", httpResponse.getResponseAsString()); assertEquals( "o=1;v=2;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
private static <K, V> ImmutableSetMultimap<K, V> copyOf( Multimap<? extends K, ? extends V> multimap, Comparator<? super V> valueComparator) { checkNotNull(multimap); // eager for GWT if (multimap.isEmpty() && valueComparator == null) { return of(); } if (multimap instanceof ImmutableSetMultimap) { @SuppressWarnings("unchecked") // safe since multimap is not writable ImmutableSetMultimap<K, V> kvMultimap = (ImmutableSetMultimap<K, V>) multimap; if (!kvMultimap.isPartialView()) { return kvMultimap; } } ImmutableMap.Builder<K, ImmutableSet<V>> builder = ImmutableMap.builder(); int size = 0; for (Entry<? extends K, ? extends Collection<? extends V>> entry : multimap.asMap().entrySet()) { K key = entry.getKey(); Collection<? extends V> values = entry.getValue(); ImmutableSet<V> set = (valueComparator == null) ? ImmutableSet.copyOf(values) : ImmutableSortedSet.copyOf(valueComparator, values); if (!set.isEmpty()) { builder.put(key, set); size += set.size(); } } return new ImmutableSetMultimap<K, V>(builder.build(), size, valueComparator); }
@Test public void testFetchContentSignedOwner() throws Exception { oauth.httpResponse = CACHEABLE; signedRequest.getOAuthArguments().setSignViewer(false); HttpResponse httpResponse = requestPipeline.execute(signedRequest); assertEquals(CACHEABLE, httpResponse); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidate by owner only service.invalidateUserResources(ImmutableSet.of("OwnerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT1").create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT1", httpResponse.getResponseAsString()); assertEquals("o=1;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); // Invalidating viewer has no effect service.invalidateUserResources(ImmutableSet.of("ViewerX"), appxToken); oauth.httpResponse = new HttpResponseBuilder(CACHEABLE).setResponseString("NEWCONTENT2").create(); httpResponse = requestPipeline.execute(signedRequest); assertEquals("NEWCONTENT1", httpResponse.getResponseAsString()); assertEquals("o=1;", httpResponse.getHeader(DefaultInvalidationService.INVALIDATION_HEADER)); assertEquals(1, cacheProvider.createCache(DefaultHttpCache.CACHE_NAME).getSize()); }
private Iterable<Artifact> getFilteredProtoSources() { // Transform the well known proto artifacts by removing the external/bazel_tools prefix if // present. Otherwise the comparison for filtering out the well known types is not possible. ImmutableSet.Builder<PathFragment> wellKnownProtoPathsBuilder = new ImmutableSet.Builder<>(); for (Artifact wellKnownProto : attributes.getWellKnownTypeProtos()) { PathFragment execPath = wellKnownProto.getExecPath(); if (execPath.startsWith(BAZEL_TOOLS_PREFIX)) { wellKnownProtoPathsBuilder.add(execPath.relativeTo(BAZEL_TOOLS_PREFIX)); } else { wellKnownProtoPathsBuilder.add(execPath); } } ImmutableSet<PathFragment> wellKnownProtoPaths = wellKnownProtoPathsBuilder.build(); // Filter out the well known types from being sent to be generated, as these protos have already // been generated and linked in libprotobuf.a. ImmutableSet.Builder<Artifact> filteredProtos = new ImmutableSet.Builder<>(); for (Artifact proto : getAllProtoSources()) { if (!wellKnownProtoPaths.contains(proto.getExecPath())) { filteredProtos.add(proto); } } return filteredProtos.build(); }
@Test public void testListTables() { // all schemas assertEquals( ImmutableSet.copyOf(metadata.listTables(SESSION, null)), ImmutableSet.of( new SchemaTableName("example", "numbers"), new SchemaTableName("example", "view_source"), new SchemaTableName("example", "view"), new SchemaTableName("tpch", "orders"), new SchemaTableName("tpch", "lineitem"), new SchemaTableName("exa_ple", "num_ers"))); // specific schema assertEquals( ImmutableSet.copyOf(metadata.listTables(SESSION, "example")), ImmutableSet.of( new SchemaTableName("example", "numbers"), new SchemaTableName("example", "view_source"), new SchemaTableName("example", "view"))); assertEquals( ImmutableSet.copyOf(metadata.listTables(SESSION, "tpch")), ImmutableSet.of( new SchemaTableName("tpch", "orders"), new SchemaTableName("tpch", "lineitem"))); assertEquals( ImmutableSet.copyOf(metadata.listTables(SESSION, "exa_ple")), ImmutableSet.of(new SchemaTableName("exa_ple", "num_ers"))); // unknown schema assertEquals(ImmutableSet.copyOf(metadata.listTables(SESSION, "unknown")), ImmutableSet.of()); }
@Test public void testUpdate() throws Exception { HierarchicalTypeDefinition<ClassType> typeDefinition = TypesUtil.createClassTypeDef( randomString(), ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE)); List<String> typesCreated = serviceClient.createType(TypesSerialization.toJson(typeDefinition, false)); assertEquals(typesCreated.size(), 1); assertEquals(typesCreated.get(0), typeDefinition.typeName); // Add attribute description typeDefinition = TypesUtil.createClassTypeDef( typeDefinition.typeName, ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), createOptionalAttrDef("description", DataTypes.STRING_TYPE)); TypesDef typeDef = TypesUtil.getTypesDef( ImmutableList.<EnumTypeDefinition>of(), ImmutableList.<StructTypeDefinition>of(), ImmutableList.<HierarchicalTypeDefinition<TraitType>>of(), ImmutableList.of(typeDefinition)); List<String> typesUpdated = serviceClient.updateType(typeDef); assertEquals(typesUpdated.size(), 1); Assert.assertTrue(typesUpdated.contains(typeDefinition.typeName)); HierarchicalTypeDefinition<ClassType> updatedType = serviceClient.getType(typeDefinition.typeName).classTypesAsJavaList().get(0); assertEquals(updatedType.attributeDefinitions.length, 2); }
@Test public void testForMultimap_domain() { Navigator<String> navigator = Navigators.forMultimap(ImmutableSetMultimap.of("a", "a1", "a", "a2", "b", "b")); assertEquals(ImmutableSet.of("a", "b"), ImmutableSet.copyOf(navigator.domain())); }
private List<HierarchicalTypeDefinition> createHiveTypes() throws Exception { ArrayList<HierarchicalTypeDefinition> typeDefinitions = new ArrayList<>(); HierarchicalTypeDefinition<ClassType> databaseTypeDefinition = TypesUtil.createClassTypeDef( "database", ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE)); typeDefinitions.add(databaseTypeDefinition); HierarchicalTypeDefinition<ClassType> tableTypeDefinition = TypesUtil.createClassTypeDef( "table", ImmutableSet.<String>of(), TypesUtil.createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE), TypesUtil.createRequiredAttrDef("description", DataTypes.STRING_TYPE), createOptionalAttrDef("columnNames", DataTypes.arrayTypeName(DataTypes.STRING_TYPE)), createOptionalAttrDef("created", DataTypes.DATE_TYPE), createOptionalAttrDef( "parameters", DataTypes.mapTypeName(DataTypes.STRING_TYPE, DataTypes.STRING_TYPE)), TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE), new AttributeDefinition( "database", "database", Multiplicity.REQUIRED, false, "database")); typeDefinitions.add(tableTypeDefinition); HierarchicalTypeDefinition<TraitType> fetlTypeDefinition = TypesUtil.createTraitTypeDef( "fetl", ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("level", DataTypes.INT_TYPE)); typeDefinitions.add(fetlTypeDefinition); return typeDefinitions; }
private ImmutableSet<AspectWithParameters> requiredAspects( AspectDefinition aspectDefinition, AspectParameters aspectParameters, Attribute attribute, Target target, Rule originalRule) { if (!(target instanceof Rule)) { return ImmutableSet.of(); } Set<AspectWithParameters> aspectCandidates = extractAspectCandidates(aspectDefinition, aspectParameters, attribute, originalRule); RuleClass ruleClass = ((Rule) target).getRuleClassObject(); ImmutableSet.Builder<AspectWithParameters> result = ImmutableSet.builder(); for (AspectWithParameters candidateClass : aspectCandidates) { ConfiguredAspectFactory candidate = (ConfiguredAspectFactory) AspectFactory.Util.create(candidateClass.getAspectFactory()); if (Sets.difference( candidate.getDefinition().getRequiredProviders(), ruleClass.getAdvertisedProviders()) .isEmpty()) { result.add(candidateClass); } } return result.build(); }
public void test_presentValue() { Currency ccy1 = TRADE.getProduct().getNonDeliverableCurrency(); Currency ccy2 = TRADE.getProduct().getSettlementCurrency(); LocalDate valDate = TRADE.getProduct().getPaymentDate().plusDays(7); FunctionConfig<FxNdfTrade> config = FxNdfFunctionGroups.discounting().functionConfig(TRADE, Measure.PRESENT_VALUE).get(); CalculationSingleFunction<FxNdfTrade, ?> function = config.createFunction(); FunctionRequirements reqs = function.requirements(TRADE); assertThat(reqs.getOutputCurrencies()).containsOnly(ccy1, ccy2); assertThat(reqs.getSingleValueRequirements()) .isEqualTo(ImmutableSet.of(DiscountCurveKey.of(ccy1), DiscountCurveKey.of(ccy2))); assertThat(reqs.getTimeSeriesRequirements()).isEqualTo(ImmutableSet.of()); assertThat(function.defaultReportingCurrency(TRADE)).hasValue(GBP); DiscountFactors df1 = SimpleDiscountFactors.of( ccy1, valDate, ConstantNodalCurve.of(Curves.discountFactors("Test", ACT_360), 0.99)); DiscountFactors df2 = SimpleDiscountFactors.of( ccy2, valDate, ConstantNodalCurve.of(Curves.discountFactors("Test", ACT_360), 0.99)); TestMarketDataMap md = new TestMarketDataMap( valDate, ImmutableMap.of(DiscountCurveKey.of(ccy1), df1, DiscountCurveKey.of(ccy2), df2), ImmutableMap.of()); assertThat(function.execute(TRADE, md)) .isEqualTo(FxConvertibleList.of(ImmutableList.of(CurrencyAmount.zero(GBP)))); }
@Test public void shouldInsertVowel_A_WithHarmony() { final SuffixFormSequence.SuffixFormSequenceRuleType RULE_TYPE = SuffixFormSequence.SuffixFormSequenceRuleType.INSERT_VOWEL_A_WITH_HARMONY; { final SuffixFormSequence.SuffixFormSequenceRule rule = new SuffixFormSequenceRuleStub(RULE_TYPE); ImmutableSet<PhoneticAttribute> phoneticAttributes = ImmutableSet.of(); assertThat(applier.apply(rule, phoneticAttributes), equalTo('a')); } { final SuffixFormSequence.SuffixFormSequenceRule rule = new SuffixFormSequenceRuleStub(RULE_TYPE); ImmutableSet<PhoneticAttribute> phoneticAttributes = ImmutableSet.of(PhoneticAttribute.LastVowelBack); assertThat(applier.apply(rule, phoneticAttributes), equalTo('a')); } { final SuffixFormSequence.SuffixFormSequenceRule rule = new SuffixFormSequenceRuleStub(RULE_TYPE); ImmutableSet<PhoneticAttribute> phoneticAttributes = ImmutableSet.of(PhoneticAttribute.LastVowelFrontal); assertThat(applier.apply(rule, phoneticAttributes), equalTo('e')); } }