Search in sources :

Example 16 with Environment

use of org.springframework.core.env.Environment in project nakadi by zalando.

the class HashPartitionStrategyCrutchTest method whenAdjustPartitionIndexThenOk.

@Test
public void whenAdjustPartitionIndexThenOk() {
    final Environment env = mock(Environment.class);
    when(env.getProperty("nakadi.hashPartitioning.overrideOrder.p3", List.class)).thenReturn(ImmutableList.of("1", "2", "0"));
    when(env.getProperty("nakadi.hashPartitioning.overrideOrder.p4", List.class)).thenReturn(ImmutableList.of("2", "0", "1", "3"));
    when(env.getProperty("nakadi.hashPartitioning.overrideOrder.p5", List.class)).thenReturn(ImmutableList.of("4", "3", "0", "2", "1"));
    final HashPartitionStrategyCrutch hashStrategyCrutch = new HashPartitionStrategyCrutch(env, 4);
    // expect no adjustment as we haven't specified any order for 2-partitions case
    assertThat(hashStrategyCrutch.adjustPartitionIndex(1, 2), equalTo(1));
    // expect adjustment
    assertThat(hashStrategyCrutch.adjustPartitionIndex(1, 3), equalTo(2));
    // expect adjustment
    assertThat(hashStrategyCrutch.adjustPartitionIndex(2, 4), equalTo(1));
    // expect no adjustment as the maxPartitionNum we specified is 3,
    // so our predefined order for 5-partitions should be ignored
    assertThat(hashStrategyCrutch.adjustPartitionIndex(0, 5), equalTo(0));
}
Also used : Environment(org.springframework.core.env.Environment) Test(org.junit.Test)

Example 17 with Environment

use of org.springframework.core.env.Environment in project nakadi by zalando.

the class HashPartitionStrategyCrutchTest method whenPartitionIndexIsWrongThenIllegalArgumentException.

@Test(expected = IllegalArgumentException.class)
public void whenPartitionIndexIsWrongThenIllegalArgumentException() {
    final Environment env = mock(Environment.class);
    when(env.getProperty("nakadi.hashPartitioning.overrideOrder.p3", List.class)).thenReturn(ImmutableList.of("1", "0", "3"));
    new HashPartitionStrategyCrutch(env, 4);
}
Also used : Environment(org.springframework.core.env.Environment) Test(org.junit.Test)

Example 18 with Environment

use of org.springframework.core.env.Environment in project dubion by valsamiq.

the class DubionApp method main.

/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(DubionApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    log.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t{}://localhost:{}\n\t" + "External: \t{}://{}:{}\n\t" + "Profile(s): \t{}\n----------------------------------------------------------", env.getProperty("spring.application.name"), protocol, env.getProperty("server.port"), protocol, InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getActiveProfiles());
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Environment(org.springframework.core.env.Environment)

Example 19 with Environment

use of org.springframework.core.env.Environment in project ArTEMiS by ls1intum.

the class ArTEMiSApp method main.

/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 * @throws UnknownHostException if the local host name could not be resolved into an address
 */
public static void main(String[] args) throws UnknownHostException {
    SpringApplication app = new SpringApplication(ArTEMiSApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    log.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t{}://localhost:{}\n\t" + "External: \t{}://{}:{}\n\t" + "Profile(s): \t{}\n----------------------------------------------------------", env.getProperty("spring.application.name"), protocol, env.getProperty("server.port"), protocol, InetAddress.getLocalHost().getHostAddress(), env.getProperty("server.port"), env.getActiveProfiles());
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Environment(org.springframework.core.env.Environment)

Example 20 with Environment

use of org.springframework.core.env.Environment in project jhipster-sample-app-cassandra by jhipster.

the class JhipsterCassandraSampleApplicationApp method main.

/**
 * Main method, used to run the application.
 *
 * @param args the command line arguments
 */
public static void main(String[] args) {
    SpringApplication app = new SpringApplication(JhipsterCassandraSampleApplicationApp.class);
    DefaultProfileUtil.addDefaultProfile(app);
    Environment env = app.run(args).getEnvironment();
    String protocol = "http";
    if (env.getProperty("server.ssl.key-store") != null) {
        protocol = "https";
    }
    String hostAddress = "localhost";
    try {
        hostAddress = InetAddress.getLocalHost().getHostAddress();
    } catch (Exception e) {
        log.warn("The host name could not be determined, using `localhost` as fallback");
    }
    log.info("\n----------------------------------------------------------\n\t" + "Application '{}' is running! Access URLs:\n\t" + "Local: \t\t{}://localhost:{}\n\t" + "External: \t{}://{}:{}\n\t" + "Profile(s): \t{}\n----------------------------------------------------------", env.getProperty("spring.application.name"), protocol, env.getProperty("server.port"), protocol, hostAddress, env.getProperty("server.port"), env.getActiveProfiles());
}
Also used : SpringApplication(org.springframework.boot.SpringApplication) Environment(org.springframework.core.env.Environment)

Aggregations

Environment (org.springframework.core.env.Environment)163 Test (org.junit.jupiter.api.Test)68 StandardEnvironment (org.springframework.core.env.StandardEnvironment)30 EnvironmentVariableUtility (com.synopsys.integration.alert.environment.EnvironmentVariableUtility)26 MockEnvironment (org.springframework.mock.env.MockEnvironment)24 SpringApplication (org.springframework.boot.SpringApplication)21 EnvironmentProcessingResult (com.synopsys.integration.alert.environment.EnvironmentProcessingResult)19 EnvironmentVariableHandler (com.synopsys.integration.alert.environment.EnvironmentVariableHandler)19 EnvironmentVariableHandlerFactory (com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory)19 HashMap (java.util.HashMap)14 ResourceLoader (org.springframework.core.io.ResourceLoader)13 Collectors (java.util.stream.Collectors)12 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)11 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)9 MutablePropertySources (org.springframework.core.env.MutablePropertySources)9 Map (java.util.Map)8 AlertConstants (com.synopsys.integration.alert.api.common.model.AlertConstants)7 ChannelKeys (com.synopsys.integration.alert.descriptor.api.model.ChannelKeys)7 EnvironmentVariableMockingUtil (com.synopsys.integration.alert.test.common.EnvironmentVariableMockingUtil)7 Predicate (java.util.function.Predicate)7