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.

DaemonTest.java 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * Copyright (C) 2017 Thomas Wolf <thomas.wolf@paranor.ch> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.transport;
  11. import static org.junit.Assert.assertEquals;
  12. import static org.junit.Assert.assertTrue;
  13. import java.net.InetSocketAddress;
  14. import org.junit.Test;
  15. /**
  16. * Daemon tests.
  17. */
  18. public class DaemonTest {
  19. @Test
  20. public void testDaemonStop() throws Exception {
  21. Daemon d = new Daemon();
  22. d.start();
  23. InetSocketAddress address = d.getAddress();
  24. assertTrue("Port should be allocated", address.getPort() > 0);
  25. assertTrue("Daemon should be running", d.isRunning());
  26. Thread.sleep(1000); // Give it time to enter accept()
  27. d.stopAndWait();
  28. // Try to start a new Daemon again on the same port
  29. d = new Daemon(address);
  30. d.start();
  31. InetSocketAddress newAddress = d.getAddress();
  32. assertEquals("New daemon should run on the same port", address,
  33. newAddress);
  34. assertTrue("Daemon should be running", d.isRunning());
  35. Thread.sleep(1000);
  36. d.stopAndWait();
  37. }
  38. @Test
  39. public void testDaemonRestart() throws Exception {
  40. Daemon d = new Daemon();
  41. d.start();
  42. InetSocketAddress address = d.getAddress();
  43. assertTrue("Port should be allocated", address.getPort() > 0);
  44. assertTrue("Daemon should be running", d.isRunning());
  45. Thread.sleep(1000);
  46. d.stopAndWait();
  47. // Re-start the same daemon
  48. d.start();
  49. InetSocketAddress newAddress = d.getAddress();
  50. assertEquals("Daemon should again run on the same port", address,
  51. newAddress);
  52. assertTrue("Daemon should be running", d.isRunning());
  53. Thread.sleep(1000);
  54. d.stopAndWait();
  55. }
  56. }