You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AppStateFactoryTest.java 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonar.application;
  21. import java.net.InetAddress;
  22. import java.util.Optional;
  23. import org.hamcrest.CoreMatchers;
  24. import org.junit.Test;
  25. import org.sonar.application.cluster.ClusterAppStateImpl;
  26. import org.sonar.application.config.TestAppSettings;
  27. import org.sonar.process.NetworkUtilsImpl;
  28. import static org.assertj.core.api.Assertions.assertThat;
  29. import static org.junit.Assume.assumeThat;
  30. import static org.sonar.process.ProcessProperties.Property.CLUSTER_ENABLED;
  31. import static org.sonar.process.ProcessProperties.Property.CLUSTER_HZ_HOSTS;
  32. import static org.sonar.process.ProcessProperties.Property.CLUSTER_NAME;
  33. import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_HOST;
  34. import static org.sonar.process.ProcessProperties.Property.CLUSTER_NODE_TYPE;
  35. import static org.sonar.process.ProcessProperties.Property.CLUSTER_SEARCH_HOSTS;
  36. public class AppStateFactoryTest {
  37. private TestAppSettings settings = new TestAppSettings();
  38. private AppStateFactory underTest = new AppStateFactory(settings);
  39. @Test
  40. public void create_cluster_implementation_if_cluster_is_enabled() {
  41. Optional<InetAddress> ip = NetworkUtilsImpl.INSTANCE.getLocalNonLoopbackIpv4Address();
  42. assumeThat(ip.isPresent(), CoreMatchers.is(true));
  43. settings.set(CLUSTER_ENABLED.getKey(), "true");
  44. settings.set(CLUSTER_NODE_TYPE.getKey(), "application");
  45. settings.set(CLUSTER_NODE_HOST.getKey(), ip.get().getHostAddress());
  46. settings.set(CLUSTER_HZ_HOSTS.getKey(), ip.get().getHostAddress());
  47. settings.set(CLUSTER_NAME.getKey(), "foo");
  48. settings.set(CLUSTER_SEARCH_HOSTS.getKey(), "localhost:9001");
  49. AppState appState = underTest.create();
  50. assertThat(appState).isInstanceOf(ClusterAppStateImpl.class);
  51. appState.close();
  52. }
  53. @Test
  54. public void cluster_implementation_is_disabled_by_default() {
  55. assertThat(underTest.create()).isInstanceOf(AppStateImpl.class);
  56. }
  57. }