|
| 1 | +/* |
| 2 | + * Licensed to Elasticsearch under one or more contributor |
| 3 | + * license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright |
| 5 | + * ownership. Elasticsearch licenses this file to you under |
| 6 | + * the Apache License, Version 2.0 (the "License"); you may |
| 7 | + * not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, |
| 13 | + * software distributed under the License is distributed on an |
| 14 | + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | + * KIND, either express or implied. See the License for the |
| 16 | + * specific language governing permissions and limitations |
| 17 | + * under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +package org.elasticsearch.packaging.test; |
| 21 | + |
| 22 | +import com.carrotsearch.randomizedtesting.annotations.TestCaseOrdering; |
| 23 | +import org.junit.Before; |
| 24 | + |
| 25 | +import java.io.IOException; |
| 26 | +import java.nio.file.Files; |
| 27 | +import java.nio.file.Path; |
| 28 | + |
| 29 | +import static org.elasticsearch.packaging.util.Archives.installArchive; |
| 30 | +import static org.elasticsearch.packaging.util.Archives.stopElasticsearch; |
| 31 | +import static org.elasticsearch.packaging.util.Archives.verifyArchiveInstallation; |
| 32 | +import static org.elasticsearch.packaging.util.FileUtils.rm; |
| 33 | +import static org.elasticsearch.packaging.util.FileUtils.slurp; |
| 34 | +import static org.elasticsearch.packaging.util.Packages.assertStatuses; |
| 35 | +import static org.elasticsearch.packaging.util.Packages.maskSysctl; |
| 36 | +import static org.elasticsearch.packaging.util.Packages.recreateTempFiles; |
| 37 | +import static org.elasticsearch.packaging.util.Packages.restartElasticsearch; |
| 38 | +import static org.elasticsearch.packaging.util.Packages.startElasticsearch; |
| 39 | +import static org.elasticsearch.packaging.util.Packages.unmaskSysctl; |
| 40 | +import static org.elasticsearch.packaging.util.Packages.verifyPackageInstallation; |
| 41 | +import static org.elasticsearch.packaging.util.Platforms.isSystemd; |
| 42 | +import static org.elasticsearch.packaging.util.ServerUtils.runElasticsearchTests; |
| 43 | +import static org.hamcrest.CoreMatchers.notNullValue; |
| 44 | +import static org.hamcrest.core.Is.is; |
| 45 | +import static org.junit.Assume.assumeThat; |
| 46 | +import static org.junit.Assume.assumeTrue; |
| 47 | + |
| 48 | +@TestCaseOrdering(TestCaseOrdering.AlphabeticOrder.class) |
| 49 | +public abstract class ServiceManagerTestCase extends PackagingTestCase { |
| 50 | + |
| 51 | + |
| 52 | + @Before |
| 53 | + public void init() { |
| 54 | + //unless 70_sysv_initd.bats is migrated this should only run for systemd |
| 55 | + assumeTrue(isSystemd()); |
| 56 | + } |
| 57 | + |
| 58 | + public void test10Install() { |
| 59 | + installation = installArchive(distribution()); |
| 60 | + verifyArchiveInstallation(installation, distribution()); |
| 61 | + } |
| 62 | + |
| 63 | + public void test20StartServer() throws IOException { |
| 64 | + assumeThat(installation, is(notNullValue())); |
| 65 | + |
| 66 | + startElasticsearch(); |
| 67 | + runElasticsearchTests(); |
| 68 | + verifyPackageInstallation(installation, distribution()); // check startup script didn't change permissions |
| 69 | + } |
| 70 | + |
| 71 | + public void test30RestartServer() throws IOException { |
| 72 | + restartElasticsearch(); |
| 73 | + runElasticsearchTests(); |
| 74 | + } |
| 75 | + |
| 76 | + public void test40StopServer() { |
| 77 | + stopElasticsearch(installation); |
| 78 | + assertStatuses(); // non deterministic |
| 79 | + } |
| 80 | + |
| 81 | + public void test45StopServerAgain() { |
| 82 | + stopElasticsearch(installation); |
| 83 | + assertStatuses(); // non deterministic |
| 84 | + } |
| 85 | + |
| 86 | + public void test50ManualStartup() throws IOException { |
| 87 | + rm(installation.pidDir); |
| 88 | + |
| 89 | + recreateTempFiles(); |
| 90 | + |
| 91 | + startElasticsearch(); |
| 92 | + |
| 93 | + final Path pidFile = installation.home.resolve("elasticsearch.pid"); |
| 94 | + |
| 95 | + assertTrue(Files.exists(pidFile)); |
| 96 | + } |
| 97 | + |
| 98 | + public void test60SystemdMask() { |
| 99 | + cleanup(); |
| 100 | + |
| 101 | + maskSysctl(); |
| 102 | + |
| 103 | + installation = installArchive(distribution()); |
| 104 | + |
| 105 | + unmaskSysctl(); |
| 106 | + } |
| 107 | + |
| 108 | + public void test70serviceFileSetsLimits() throws IOException { |
| 109 | + cleanup(); |
| 110 | + |
| 111 | + installation = installArchive(distribution()); |
| 112 | + |
| 113 | + startElasticsearch(); |
| 114 | + |
| 115 | + final Path pidFile = installation.home.resolve("elasticsearch.pid"); |
| 116 | + assertTrue(Files.exists(pidFile)); |
| 117 | + String pid = slurp(pidFile).trim(); |
| 118 | + |
| 119 | + |
| 120 | + } |
| 121 | + |
| 122 | +} |
0 commit comments