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.

ComputeEngineImplTest.java 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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.ce;
  21. import java.util.Properties;
  22. import org.junit.Rule;
  23. import org.junit.Test;
  24. import org.junit.rules.ExpectedException;
  25. import org.sonar.ce.container.ComputeEngineStatus;
  26. import org.sonar.ce.container.ComputeEngineContainer;
  27. import org.sonar.process.Props;
  28. public class ComputeEngineImplTest {
  29. @Rule
  30. public ExpectedException expectedException = ExpectedException.none();
  31. private ComputeEngineContainer computeEngineContainer = new NoOpComputeEngineContainer();
  32. private ComputeEngine underTest = new ComputeEngineImpl(new Props(new Properties()), computeEngineContainer);
  33. @Test
  34. public void startup_throws_ISE_when_called_twice() {
  35. underTest.startup();
  36. expectedException.expect(IllegalStateException.class);
  37. expectedException.expectMessage("startup() can not be called multiple times");
  38. underTest.startup();
  39. }
  40. @Test
  41. public void stopProcessing_throws_ISE_if_startup_was_not_called_before() {
  42. expectedException.expect(IllegalStateException.class);
  43. expectedException.expectMessage("stopProcessing() must not be called before startup()");
  44. underTest.stopProcessing();
  45. }
  46. @Test
  47. public void stopProcessing_throws_ISE_if_called_after_shutdown() {
  48. underTest.startup();
  49. underTest.shutdown();
  50. expectedException.expect(IllegalStateException.class);
  51. expectedException.expectMessage("stopProcessing() can not be called after shutdown()");
  52. underTest.stopProcessing();
  53. }
  54. @Test
  55. public void stopProcessing_throws_ISE_if_called_twice() {
  56. underTest.startup();
  57. underTest.stopProcessing();
  58. expectedException.expect(IllegalStateException.class);
  59. expectedException.expectMessage("stopProcessing() can not be called multiple times");
  60. underTest.stopProcessing();
  61. }
  62. @Test
  63. public void shutdown_throws_ISE_if_startup_was_not_called_before() {
  64. expectedException.expect(IllegalStateException.class);
  65. expectedException.expectMessage("shutdown() must not be called before startup()");
  66. underTest.shutdown();
  67. }
  68. @Test
  69. public void shutdown_throws_ISE_if_called_twice() {
  70. underTest.startup();
  71. underTest.shutdown();
  72. expectedException.expect(IllegalStateException.class);
  73. expectedException.expectMessage("shutdown() can not be called multiple times");
  74. underTest.shutdown();
  75. }
  76. private static class NoOpComputeEngineContainer implements ComputeEngineContainer {
  77. @Override
  78. public void setComputeEngineStatus(ComputeEngineStatus computeEngineStatus) {
  79. }
  80. @Override
  81. public ComputeEngineContainer start(Props props) {
  82. return this;
  83. }
  84. @Override
  85. public ComputeEngineContainer stopWorkers() {
  86. return this;
  87. }
  88. @Override
  89. public ComputeEngineContainer stop() {
  90. return this;
  91. }
  92. }
  93. }