|
| 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 org.elasticsearch.packaging.util.Platforms; |
| 23 | +import org.elasticsearch.packaging.util.ServerUtils; |
| 24 | +import org.elasticsearch.packaging.util.Shell; |
| 25 | +import org.junit.BeforeClass; |
| 26 | + |
| 27 | +import java.nio.file.Files; |
| 28 | + |
| 29 | +import static org.elasticsearch.packaging.util.FileUtils.assertPathsExist; |
| 30 | +import static org.hamcrest.CoreMatchers.anyOf; |
| 31 | +import static org.hamcrest.CoreMatchers.equalTo; |
| 32 | +import static org.junit.Assume.assumeFalse; |
| 33 | +import static org.junit.Assume.assumeTrue; |
| 34 | + |
| 35 | +public class SysVInitTests extends PackagingTestCase { |
| 36 | + |
| 37 | + @BeforeClass |
| 38 | + public static void filterDistros() { |
| 39 | + assumeTrue("rpm or deb", distribution.isPackage()); |
| 40 | + assumeTrue(Platforms.isSysVInit()); |
| 41 | + assumeFalse(Platforms.isSystemd()); |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + public void startElasticsearch() throws Exception { |
| 46 | + sh.run("service elasticsearch start"); |
| 47 | + ServerUtils.waitForElasticsearch(installation); |
| 48 | + sh.run("service elasticsearch status"); |
| 49 | + } |
| 50 | + |
| 51 | + @Override |
| 52 | + public void stopElasticsearch() { |
| 53 | + sh.run("service elasticsearch stop"); |
| 54 | + } |
| 55 | + |
| 56 | + public void test10Install() throws Exception { |
| 57 | + install(); |
| 58 | + } |
| 59 | + |
| 60 | + public void test20Start() throws Exception { |
| 61 | + startElasticsearch(); |
| 62 | + assertTrue("gc logs exist", Files.exists(installation.logs.resolve("gc.log"))); |
| 63 | + ServerUtils.runElasticsearchTests(); |
| 64 | + sh.run("service elasticsearch status"); // returns 0 exit status when ok |
| 65 | + } |
| 66 | + |
| 67 | + public void test21Restart() throws Exception { |
| 68 | + sh.run("service elasticsearch restart"); |
| 69 | + sh.run("service elasticsearch status"); // returns 0 exit status when ok |
| 70 | + } |
| 71 | + |
| 72 | + public void test22Stop() throws Exception { |
| 73 | + stopElasticsearch(); |
| 74 | + Shell.Result status = sh.runIgnoreExitCode("service elasticsearch status"); |
| 75 | + assertThat(status.exitCode, anyOf(equalTo(3), equalTo(4))); |
| 76 | + } |
| 77 | + |
| 78 | + public void test30PidDirCreation() throws Exception { |
| 79 | + // Simulates the behavior of a system restart: |
| 80 | + // the PID directory is deleted by the operating system |
| 81 | + // but it should not block ES from starting |
| 82 | + // see https://github.com/elastic/elasticsearch/issues/11594 |
| 83 | + |
| 84 | + sh.run("rm -rf " + installation.pidDir); |
| 85 | + startElasticsearch(); |
| 86 | + assertPathsExist(installation.pidDir.resolve("elasticsearch.pid")); |
| 87 | + stopElasticsearch(); |
| 88 | + } |
| 89 | + |
| 90 | + public void test31MaxMapTooSmall() throws Exception { |
| 91 | + sh.run("sysctl -q -w vm.max_map_count=262140"); |
| 92 | + startElasticsearch(); |
| 93 | + Shell.Result result = sh.run("sysctl -n vm.max_map_count"); |
| 94 | + String maxMapCount = result.stdout.strip(); |
| 95 | + sh.run("service elasticsearch stop"); |
| 96 | + assertThat(maxMapCount, equalTo("262144")); |
| 97 | + } |
| 98 | + |
| 99 | + public void test32MaxMapBigEnough() throws Exception { |
| 100 | + // Ensures that if $MAX_MAP_COUNT is greater than the set |
| 101 | + // value on the OS we do not attempt to update it. |
| 102 | + sh.run("sysctl -q -w vm.max_map_count=262145"); |
| 103 | + startElasticsearch(); |
| 104 | + Shell.Result result = sh.run("sysctl -n vm.max_map_count"); |
| 105 | + String maxMapCount = result.stdout.strip(); |
| 106 | + sh.run("service elasticsearch stop"); |
| 107 | + assertThat(maxMapCount, equalTo("262145")); |
| 108 | + } |
| 109 | + |
| 110 | +} |
0 commit comments