EVCacheServerEnvironmentPostProcessor implements EnvironmentPostProcessor, Ordered { @Override public void postProcessEnvironment(final ConfigurableEnvironment environment, final SpringApplication application) { final Map<String, Object> source = new ConcurrentHashMap<>(); if (!environment.containsProperty("eureka.instance.asg-name")) { final String asgName = environment.getProperty("evcache.asg-name", "DEFAULT"); source.put("eureka.instance.asg-name", asgName); LOGGER.warn("`eureka.instance.asg-name` is Missing, set `{}`", asgName); } putMetadataIfAbsent(source, environment, "evcache.port"); putMetadataIfAbsent(source, environment, "evcache.secure.port"); putMetadataIfAbsent(source, environment, "rend.port"); putMetadataIfAbsent(source, environment, "rend.batch.port"); putMetadataIfAbsent(source, environment, "udsproxy.memcached.port"); putMetadataIfAbsent(source, environment, "udsproxy.memento.port"); environment.getPropertySources() .addLast(new MapPropertySource("evcache-server", source)); }  @Override void postProcessEnvironment(final ConfigurableEnvironment environment, final SpringApplication application); @Override int getOrder();  }
@Test void should_be_equal_default_when_not_exist_asg_name() { processor.postProcessEnvironment(environment, null); assertThat(environment.getProperty("eureka.instance.asg-name")).isEqualTo("DEFAULT"); }
@Test void should_be_not_change_when_exist_asg_name() { environment.getPropertySources() .addLast(new MapPropertySource("test", singletonMap("eureka.instance.asg-name", "asg"))); processor.postProcessEnvironment(environment, null); assertThat(environment.getProperty("eureka.instance.asg-name")).isEqualTo("asg"); }
@Test void should_be_set_when_exist_asg_name() { environment.getPropertySources() .addLast(new MapPropertySource("test", singletonMap("evcache.asg-name", "group"))); processor.postProcessEnvironment(environment, null); assertThat(environment.getProperty("eureka.instance.asg-name")).isEqualTo("group"); }
@Test void should_be_not_set_when_not_exist_evcache_port() { processor.postProcessEnvironment(environment, null); assertThat(environment.containsProperty("eureka.instance.metadata-map.evcache.port")).isFalse(); }
@Test void should_be_set_when_exist_evcache_port() { environment.getPropertySources().addLast(new MapPropertySource("test", singletonMap("evcache.port", 11211))); processor.postProcessEnvironment(environment, null); assertThat(environment.getProperty("eureka.instance.metadata-map.evcache.port")).isEqualTo("11211"); }
@Test void should_be_not_set_when_not_exist_evcache_secure_port() { processor.postProcessEnvironment(environment, null); assertThat(environment.containsProperty("eureka.instance.metadata-map.evcache.secure.port")).isFalse(); }
@Test void should_be_set_when_exist_evcache_secure_port() { environment.getPropertySources() .addLast(new MapPropertySource("test", singletonMap("evcache.secure.port", 11411))); processor.postProcessEnvironment(environment, null); assertThat(environment.getProperty("eureka.instance.metadata-map.evcache.secure.port")).isEqualTo("11411"); }
@Test void should_be_not_set_when_not_exist_rend_port() { processor.postProcessEnvironment(environment, null); assertThat(environment.containsProperty("eureka.instance.metadata-map.rend.port")).isFalse(); }
@Test void should_be_set_when_exist_rend_port() { environment.getPropertySources().addLast(new MapPropertySource("test", singletonMap("rend.port", 11211))); processor.postProcessEnvironment(environment, null); assertThat(environment.getProperty("eureka.instance.metadata-map.rend.port")).isEqualTo("11211"); }
@Test void should_be_not_set_when_not_exist_rend_batch_port() { processor.postProcessEnvironment(environment, null); assertThat(environment.containsProperty("eureka.instance.metadata-map.rend.batch.port")).isFalse(); }
@Test void should_be_set_when_exist_rend_batch_port() { environment.getPropertySources().addLast(new MapPropertySource("test", singletonMap("rend.batch.port", 11211))); processor.postProcessEnvironment(environment, null); assertThat(environment.getProperty("eureka.instance.metadata-map.rend.batch.port")).isEqualTo("11211"); }
@Test void should_be_not_set_when_not_exist_udsproxy_memcached_port() { processor.postProcessEnvironment(environment, null); assertThat(environment.containsProperty("eureka.instance.metadata-map.udsproxy.memcached.port")).isFalse(); }
@Test void should_be_set_when_exist_udsproxy_memcached_port() { environment.getPropertySources() .addLast(new MapPropertySource("test", singletonMap("udsproxy.memcached.port", 11211))); processor.postProcessEnvironment(environment, null); assertThat(environment.getProperty("eureka.instance.metadata-map.udsproxy.memcached.port")).isEqualTo("11211"); }
@Test void should_be_not_set_when_not_exist_udsproxy_memento_port() { processor.postProcessEnvironment(environment, null); assertThat(environment.containsProperty("eureka.instance.metadata-map.udsproxy.memento.port")).isFalse(); }
@Test void should_be_set_when_exist_udsproxy_memento_port() { environment.getPropertySources() .addLast(new MapPropertySource("test", singletonMap("udsproxy.memento.port", 11211))); processor.postProcessEnvironment(environment, null); assertThat(environment.getProperty("eureka.instance.metadata-map.udsproxy.memento.port")).isEqualTo("11211"); }