Java Code Examples for java.util.Set#of()

The following examples show how to use java.util.Set#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResetSettingsPlanTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
public void testReset() throws Exception {
    Set<Symbol> settings = Set.of(Literal.of("stats"));

    Settings expected = Settings.builder()
        .put("stats.breaker.log.operations.limit", (String) null)
        .put("stats.breaker.log.operations.overhead", (String) null)
        .put("stats.breaker.log.jobs.limit", (String) null)
        .put("stats.breaker.log.jobs.overhead", (String) null)
        .put("stats.enabled", (String) null)
        .put("stats.jobs_log_size", (String) null)
        .put("stats.jobs_log_expiration", (String) null)
        .put("stats.jobs_log_filter", (String) null)
        .put("stats.jobs_log_persistent_filter", (String) null)
        .put("stats.operations_log_size", (String) null)
        .put("stats.operations_log_expiration", (String) null)
        .put("stats.service.interval", (String) null)
        .build();

    assertThat(buildSettingsFrom(settings, symbolEvaluator(Row.EMPTY)), is(expected));

}
 
Example 2
Source File: RedefineModuleUtils.java    From pinpoint with Apache License 2.0 6 votes vote down vote up
static void addReads(Instrumentation instrumentation, Module module, Set<Module> extraReads) {
        if (instrumentation == null) {
            throw new NullPointerException("instrumentation");
        }
        if (module == null) {
            throw new NullPointerException("module");
        }
        if (extraReads == null) {
            throw new NullPointerException("extraReads");
        }

        // for debug
//        final Set<Module> extraReads0 = extraReads;
        final Map<String, Set<Module>> extraExports = Map.of();
        final Map<String, Set<Module>> extraOpens = Map.of();
        final Set<Class<?>> extraUses = Set.of();
        final Map<Class<?>, List<Class<?>>> extraProvides = Map.of();
        instrumentation.redefineModule(module, extraReads, extraExports, extraOpens, extraUses, extraProvides);
    }
 
Example 3
Source File: SharedLoadBalancerService.java    From vespa with Apache License 2.0 6 votes vote down vote up
@Override
public LoadBalancerInstance create(LoadBalancerSpec spec, boolean force) {
    var proxyNodes = new ArrayList<>(nodeRepository.getNodes(NodeType.proxy));
    proxyNodes.sort(hostnameComparator);

    if (proxyNodes.size() == 0) {
        throw new IllegalStateException("Missing proxy nodes in node repository");
    }

    var firstProxyNode = proxyNodes.get(0);
    var networkNames = proxyNodes.stream()
                                 .flatMap(node -> node.ipAddresses().stream())
                                 .map(SharedLoadBalancerService::withPrefixLength)
                                 .collect(Collectors.toSet());

    return new LoadBalancerInstance(
            HostName.from(firstProxyNode.hostname()),
            Optional.empty(),
            Set.of(4080, 4443),
            networkNames,
            spec.reals()
    );
}
 
Example 4
Source File: AzureEnvironmentNetworkConverterTest.java    From cloudbreak with Apache License 2.0 6 votes vote down vote up
private Set<CreatedSubnet> createCreatedSubnets() {
    CreatedSubnet createdSubnet1 = new CreatedSubnet();
    createdSubnet1.setSubnetId(SUBNET_1);
    createdSubnet1.setAvailabilityZone(AZ_1);
    createdSubnet1.setCidr(SUBNET_CIDR_1);
    createdSubnet1.setPublicSubnet(true);

    CreatedSubnet createdSubnet2 = new CreatedSubnet();
    createdSubnet2.setSubnetId(SUBNET_2);
    createdSubnet2.setAvailabilityZone(AZ_2);
    createdSubnet2.setCidr(SUBNET_CIDR_2);
    createdSubnet2.setPublicSubnet(true);

    CreatedSubnet createdSubnet3 = new CreatedSubnet();
    createdSubnet3.setSubnetId(SUBNET_3);
    createdSubnet3.setAvailabilityZone(AZ_3);
    createdSubnet3.setCidr(SUBNET_CIDR_3);
    createdSubnet3.setPublicSubnet(true);
    return Set.of(createdSubnet1, createdSubnet2, createdSubnet3);
}
 
Example 5
Source File: DescriptorMetadataActions.java    From blackduck-alert with Apache License 2.0 6 votes vote down vote up
private Set<DescriptorMetadata> getDescriptors(@Nullable String name, @Nullable String type, @Nullable String context,
    BiFunction<Set<Descriptor>, ConfigContextEnum, Set<DescriptorMetadata>> generatorFunction) {
    Predicate<Descriptor> filter = Descriptor::hasUIConfigs;
    if (name != null) {
        filter = filter.and(descriptor -> name.equalsIgnoreCase(descriptor.getDescriptorKey().getUniversalKey()));
    }

    DescriptorType typeEnum = EnumUtils.getEnumIgnoreCase(DescriptorType.class, type);
    if (typeEnum != null) {
        filter = filter.and(descriptor -> typeEnum.equals(descriptor.getType()));
    } else if (type != null) {
        return Set.of();
    }

    ConfigContextEnum contextEnum = EnumUtils.getEnumIgnoreCase(ConfigContextEnum.class, context);
    if (contextEnum != null) {
        filter = filter.and(descriptor -> descriptor.hasUIConfigForType(contextEnum));
    } else if (context != null) {
        return Set.of();
    }

    Set<Descriptor> filteredDescriptors = filter(descriptors, filter);
    return generatorFunction.apply(filteredDescriptors, contextEnum);
}
 
Example 6
Source File: BlueprintServiceTest.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetAllAvailableViewInWorkspaceGivenHasSdxReadyWhenWithSdxReady() {
    Set<BlueprintView> blueprintViews = Set.of(getBlueprintView("bp1", ResourceStatus.DEFAULT, true),
            getBlueprintView("bp2", ResourceStatus.DEFAULT, false),
            getBlueprintView("bp3", ResourceStatus.DEFAULT, false));
    when(blueprintViewRepository.findAllByNotDeletedInWorkspace(1L)).thenReturn(blueprintViews);
    Set<BlueprintView> result = underTest.getAllAvailableViewInWorkspaceAndFilterBySdxReady(1L, true);
    assertEquals(3, result.size());
    assertTrue(result.stream().map(BlueprintView::getName).collect(Collectors.toSet()).containsAll(Set.of("bp1", "bp2", "bp3")));
}
 
Example 7
Source File: Java9Module.java    From pinpoint with Apache License 2.0 5 votes vote down vote up
@Override
    public void addUses(Class<?> target) {
        if (target == null) {
            throw new NullPointerException("target");
        }
//        logger.info("addUses module:" + module.getName() +" target:" + target);
        // for debug
        final Set<Class<?>> extraUses = Set.of(target);
        RedefineModuleUtils.addUses(instrumentation, module, extraUses);
    }
 
Example 8
Source File: PostInstallFreeIpaFailedToUpscaleFailureEventConverter.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Override
public UpscaleFailureEvent convert(Object payload) {
    PostInstallFreeIpaFailed result = (PostInstallFreeIpaFailed) payload;
    UpscaleFailureEvent event = new UpscaleFailureEvent(result.getResourceId(), "Bootstrapping mahcines", Set.of(), Map.of(),
            new Exception("Payload failed: " + payload));
    return event;
}
 
Example 9
Source File: FreeIpaUpscaleActions.java    From cloudbreak with Apache License 2.0 5 votes vote down vote up
@Bean(name = "UPSCALE_EXTEND_METADATA_STATE")
public Action<?, ?> extendMetadataAction() {
    return new AbstractUpscaleAction<>(StackEvent.class) {

        private final Set<InstanceStatus> unusedInstanceStatuses = Set.of(InstanceStatus.CREATE_REQUESTED, InstanceStatus.CREATED);

        @Override
        protected void doExecute(StackContext context, StackEvent payload, Map<Object, Object> variables) {
            Stack stack = context.getStack();
            stackUpdater.updateStackStatus(stack.getId(), getInProgressStatus(variables), "Extending metadata");

            List<CloudInstance> allKnownInstances = cloudStackConverter.buildInstances(stack);
            List<Resource> resources = resourceService.findAllByStackId(stack.getId());
            List<CloudResource> cloudResources = resourceConverter.convert(resources);
            List<CloudInstance> newCloudInstances = allKnownInstances.stream()
                    .filter(this::isNewInstances)
                    .collect(Collectors.toList());
            CollectMetadataRequest request = new CollectMetadataRequest(context.getCloudContext(), context.getCloudCredential(), cloudResources,
                    newCloudInstances, allKnownInstances);

            sendEvent(context, request.selector(), request);
        }

        private boolean isNewInstances(CloudInstance cloudInstance) {
            return unusedInstanceStatuses.contains(cloudInstance.getTemplate().getStatus());
        }
    };
}
 
Example 10
Source File: AppUserDetail.java    From springsecuritytotp with MIT License 5 votes vote down vote up
public AppUserDetail(AppUserRecord user) {
  this.appUserId = user.getId();
  this.username = user.getUsername();
  this.authorities = Set.of();
  this.secret = user.getSecret();
  this.enabled = Objects.requireNonNullElse(user.getEnabled(), false);
}
 
Example 11
Source File: DefaultAuditUtilityTest.java    From blackduck-alert with Apache License 2.0 4 votes vote down vote up
@Test
public void convertToAuditEntryModelFromNotificationTest() throws Exception {
    Long id = 1L;
    Long providerConfigId = 2L;
    String provider = "provider-test";
    String providerConfigName = "providerConfigName-test";
    String notificationType = "notificationType-test";
    String content = "content-test";
    OffsetDateTime timeLastSent = DateUtils.createCurrentDateTimestamp();
    OffsetDateTime timeCreated = timeLastSent.minusSeconds(10);
    Long auditEntryId = 3L;
    String channelName = "test-channel.common.name-value";
    String eventType = "test-channel.common.channel.name-value";

    AuditEntryRepository auditEntryRepository = Mockito.mock(AuditEntryRepository.class);
    AuditNotificationRepository auditNotificationRepository = Mockito.mock(AuditNotificationRepository.class);
    ConfigurationAccessor configurationAccessor = Mockito.mock(ConfigurationAccessor.class);

    ContentConverter contentConverter = new ContentConverter(gson, new DefaultConversionService());

    AlertNotificationModel alertNotificationModel = new AlertNotificationModel(id, providerConfigId, provider, providerConfigName, notificationType, content, DateUtils.createCurrentDateTimestamp(),
        DateUtils.createCurrentDateTimestamp());
    AuditNotificationRelation auditNotificationRelation = new AuditNotificationRelation(auditEntryId, alertNotificationModel.getId());
    AuditEntryEntity auditEntryEntity = new AuditEntryEntity(UUID.randomUUID(), timeCreated, timeLastSent, AuditEntryStatus.SUCCESS.name(), null, null);

    Mockito.when(auditNotificationRepository.findByNotificationId(Mockito.any())).thenReturn(List.of(auditNotificationRelation));
    Mockito.when(auditEntryRepository.findAllById(Mockito.any())).thenReturn(List.of(auditEntryEntity));

    ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(10L, 11L, "createdAt-test", "lastUpdate-test", ConfigContextEnum.DISTRIBUTION);
    ConfigurationFieldModel configurationFieldModel = ConfigurationFieldModel.create("channel.common.name");
    configurationFieldModel.setFieldValue("test-channel.common.name-value");
    ConfigurationFieldModel configurationFieldModel2 = ConfigurationFieldModel.create("channel.common.channel.name");
    configurationFieldModel2.setFieldValue("test-channel.common.channel.name-value");
    configurationModel.put(configurationFieldModel);
    configurationModel.put(configurationFieldModel2);

    ConfigurationJobModel configurationJobModel = new ConfigurationJobModel(UUID.randomUUID(), Set.of(configurationModel));
    Mockito.when(configurationAccessor.getJobById(Mockito.any())).thenReturn(Optional.of(configurationJobModel));

    DefaultAuditUtility auditUtility = new DefaultAuditUtility(auditEntryRepository, auditNotificationRepository, configurationAccessor, null, contentConverter);
    AuditEntryModel testAuditEntryModel = auditUtility.convertToAuditEntryModelFromNotification(alertNotificationModel);

    assertEquals(id, Long.valueOf(testAuditEntryModel.getId()));
    assertNotNull(testAuditEntryModel.getNotification());
    assertFalse(testAuditEntryModel.getJobs().isEmpty());
    assertEquals(1, testAuditEntryModel.getJobs().size());
    JobAuditModel testJob = testAuditEntryModel.getJobs().get(0);
    assertEquals(channelName, testJob.getName());
    assertEquals(eventType, testJob.getEventType());
    assertEquals(AuditEntryStatus.SUCCESS.getDisplayName(), testAuditEntryModel.getOverallStatus());
    assertEquals(DateUtils.formatDate(timeLastSent, DateUtils.AUDIT_DATE_FORMAT), testAuditEntryModel.getLastSent());
}
 
Example 12
Source File: OrchestratorImplTest.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Test
public void testGetHost() throws Exception {
    ClusterControllerClientFactory clusterControllerClientFactory = new ClusterControllerClientFactoryMock();
    StatusService statusService = new ZkStatusService(
            new MockCurator(),
            mock(Metric.class),
            new TestTimer(),
            new DummyAntiServiceMonitor());

    HostName hostName = new HostName("host.yahoo.com");
    TenantId tenantId = new TenantId("tenant");
    ApplicationInstanceId applicationInstanceId =
            new ApplicationInstanceId("applicationInstanceId");
    ApplicationInstanceReference reference = new ApplicationInstanceReference(
            tenantId,
            applicationInstanceId);

    ApplicationInstance applicationInstance =
            new ApplicationInstance(
                    tenantId,
                    applicationInstanceId,
                    Set.of(new ServiceCluster(
                            new ClusterId("clusterId"),
                            new ServiceType("serviceType"),
                            Set.of(new ServiceInstance(
                                           new ConfigId("configId1"),
                                           hostName,
                                           ServiceStatus.UP),
                                   new ServiceInstance(
                                           new ConfigId("configId2"),
                                           hostName,
                                           ServiceStatus.NOT_CHECKED)))));

    ServiceMonitor serviceMonitor = () -> new ServiceModel(Map.of(reference, applicationInstance));

    orchestrator = new OrchestratorImpl(new HostedVespaPolicy(new HostedVespaClusterPolicy(), clusterControllerClientFactory, applicationApiFactory),
                                        clusterControllerClientFactory,
                                        statusService,
                                        serviceMonitor,
                                        0,
                                        new ManualClock(),
                                        applicationApiFactory,
                                        flagSource);

    orchestrator.setNodeStatus(hostName, HostStatus.ALLOWED_TO_BE_DOWN);

    Host host = orchestrator.getHost(hostName);
    assertEquals(reference, host.getApplicationInstanceReference());
    assertEquals(hostName, host.getHostName());
    assertEquals(HostStatus.ALLOWED_TO_BE_DOWN, host.getHostInfo().status());
    assertTrue(host.getHostInfo().suspendedSince().isPresent());
    assertEquals(2, host.getServiceInstances().size());
}
 
Example 13
Source File: AzureAcceleratedNetworkValidatorTest.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
private Set<String> getOtherVms() {
    return Set.of("E4_Flex", "SQLG5_IaaS", "AZAP_Performance_ComputeV17C_12", "SQLG5-80m", "SQLG6", "SQLDCGen6_2");
}
 
Example 14
Source File: CollectionUtil.java    From Java-9-Cookbook with MIT License 4 votes vote down vote up
public static Set<String> set(String ... args){
	System.out.println("Using factory methods");
	return Set.of(args);
}
 
Example 15
Source File: CloudbreakHaApplication.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Override
public Set<Long> getAllDeletingResources() {
    Set<Long> stackIds = InMemoryStateStore.getAllStackId();
    return stackIds.isEmpty() ? Set.of() : stackService.getStatuses(stackIds).stream()
        .filter(ss -> DELETE_STATUSES.contains(ss.getStatus().getStatus())).map(StackStatusView::getId).collect(Collectors.toSet());
}
 
Example 16
Source File: PartyInfoServiceTest.java    From tessera with Apache License 2.0 4 votes vote down vote up
@Before
public void onSetUp() {

    this.partyInfoStore = mock(PartyInfoStore.class);
    this.enclave = mock(Enclave.class);
    this.payloadPublisher = mock(PayloadPublisher.class);
    this.knownPeerChecker = mock(KnownPeerChecker.class);

    final KnownPeerCheckerFactory knownPeerCheckerFactory = mock(KnownPeerCheckerFactory.class);
    when(knownPeerCheckerFactory.create(anySet())).thenReturn(knownPeerChecker);

    RUNTIME_CONTEXT
            .setP2pServerUri(java.net.URI.create(URI))
            .setPeers(singletonList(java.net.URI.create("http://other-node.com:8080")))
            .setRemoteKeyValidation(true);

    this.partyInfoService =
            new PartyInfoServiceImpl(partyInfoStore, enclave, payloadPublisher, knownPeerCheckerFactory);

    verifyNoMoreInteractions(partyInfoStore);
    verifyNoMoreInteractions(enclave);
    verifyNoMoreInteractions(payloadPublisher);

    PartyInfo storedPartyInfo = mock(PartyInfo.class);
    when(storedPartyInfo.getUrl()).thenReturn(URI);

    when(partyInfoStore.getPartyInfo()).thenReturn(storedPartyInfo);

    final Set<PublicKey> ourKeys =
            Set.of(PublicKey.from("some-key".getBytes()), PublicKey.from("another-public-key".getBytes()));

    when(enclave.getPublicKeys()).thenReturn(ourKeys);

    partyInfoService.populateStore();

    verify(partyInfoStore).getPartyInfo();
    verify(partyInfoStore).store(any(PartyInfo.class));
    verify(enclave).getPublicKeys();

    verifyNoMoreInteractions(partyInfoStore);
    verifyNoMoreInteractions(enclave);
    verifyNoMoreInteractions(payloadPublisher);

    reset(partyInfoStore, enclave, payloadPublisher);
}
 
Example 17
Source File: SetFactories.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=IllegalArgumentException.class)
public void dupsDisallowed5() {
    Set<String> set = Set.of("a", "b", "c", "d", "a");
}
 
Example 18
Source File: SupportedPlatforms.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
public SupportedPlatforms(String[] freeIpa) {
    this.freeIpa = freeIpa == null ? Set.of() : Set.of(freeIpa);
}
 
Example 19
Source File: RedbeamsHaApplication.java    From cloudbreak with Apache License 2.0 4 votes vote down vote up
@Override
public Set<Long> getAllDeletingResources() {
    Set<Long> allResourcesOfThisNode = redbeamsInMemoryStateStoreService.getAll();
    return allResourcesOfThisNode.isEmpty() ? Set.of() : dbStackService.findAllDeletingById(allResourcesOfThisNode);
}
 
Example 20
Source File: CollectionFactoryMethods.java    From blog-tutorials with MIT License 3 votes vote down vote up
public static void main(String[] args) {
	final List<String> names = List.of("Mike", "Duke", "Paul");

	final Map<Integer, String> user = Map.of(1, "Mike", 2, "Duke");
	final Map<Integer, String> admins = Map.ofEntries(Map.entry(1, "Tom"), Map.entry(2, "Paul"));

	final Set<String> server = Set.of("WildFly", "Open Liberty", "Payara", "TomEE");

	// names.add("Tom"); throws java.lang.UnsupportedOperationException -> unmodifiable collection is created
}