-
Notifications
You must be signed in to change notification settings - Fork 24.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate SysV init tests from bats to java packaging #51077
Changes from 1 commit
44972af
4244e59
dfde59c
8f6e6fd
deac6cd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.packaging.test; | ||
|
||
import org.elasticsearch.packaging.util.Platforms; | ||
import org.elasticsearch.packaging.util.ServerUtils; | ||
import org.elasticsearch.packaging.util.Shell; | ||
import org.junit.BeforeClass; | ||
|
||
import java.nio.file.Files; | ||
|
||
import static org.elasticsearch.packaging.util.FileUtils.assertPathsExist; | ||
import static org.hamcrest.CoreMatchers.anyOf; | ||
import static org.hamcrest.CoreMatchers.containsString; | ||
import static org.hamcrest.CoreMatchers.equalTo; | ||
import static org.junit.Assume.assumeTrue; | ||
|
||
public class SysVInitTests extends PackagingTestCase { | ||
|
||
@BeforeClass | ||
public static void filterDistros() { | ||
assumeTrue("rpm or deb", distribution.isPackage()); | ||
assumeTrue(Platforms.isSysVInit()); | ||
assumeTrue(Platforms.isSystemd()); | ||
} | ||
|
||
@Override | ||
public void startElasticsearch() throws Exception { | ||
// since some systems have both sysv and systemd, we need to be explicit here to use sysv | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I looks like we skip this when systemd is around. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed this comment is out of date. I do like being more epxlicit here and using the |
||
sh.run("service elasticsearch start"); | ||
ServerUtils.waitForElasticsearch(installation); | ||
sh.run("service elasticsearch status"); | ||
} | ||
|
||
@Override | ||
public void stopElasticsearch() { | ||
sh.run("service elasticsearch stop"); | ||
} | ||
|
||
public void assertStatus(int code, String msg) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Leftover from a previous iteration. Removed. |
||
Shell.Result result = sh.runIgnoreExitCode("service elasticsearch status"); | ||
assertThat(result.exitCode, equalTo(code)); | ||
if (msg != null) { | ||
assertThat(result.stdout, containsString(msg)); | ||
} | ||
} | ||
|
||
public void test10Install() throws Exception { | ||
install(); | ||
} | ||
|
||
public void test20Start() throws Exception { | ||
startElasticsearch(); | ||
assertTrue("gc logs exist", Files.exists(installation.logs.resolve("gc.log"))); | ||
ServerUtils.runElasticsearchTests(); | ||
sh.run("service elasticsearch status"); // returns 0 exit status when ok | ||
} | ||
|
||
public void test21Restart() throws Exception { | ||
sh.run("service elasticsearch restart"); | ||
sh.run("service elasticsearch status"); // returns 0 exit status when ok | ||
} | ||
|
||
public void test22Stop() throws Exception { | ||
stopElasticsearch(); | ||
Shell.Result status = sh.runIgnoreExitCode("service elasticsearch status"); | ||
assertThat(status.exitCode, anyOf(equalTo(3), equalTo(4))); | ||
} | ||
|
||
public void test30PidDirCreation() throws Exception { | ||
// Simulates the behavior of a system restart: | ||
// the PID directory is deleted by the operating system | ||
// but it should not block ES from starting | ||
// see https://github.com/elastic/elasticsearch/issues/11594 | ||
|
||
sh.run("rm -rf " + installation.pidDir); | ||
startElasticsearch(); | ||
assertPathsExist(installation.pidDir.resolve("elasticsearch.pid")); | ||
stopElasticsearch(); | ||
} | ||
|
||
public void test31MaxMapTooSmall() throws Exception { | ||
sh.run("sysctl -q -w vm.max_map_count=262140"); | ||
startElasticsearch(); | ||
Shell.Result result = sh.run("sysctl -n vm.max_map_count"); | ||
String maxMapCount = result.stdout.strip(); | ||
sh.run("service elasticsearch stop"); | ||
assertThat(maxMapCount, equalTo("262144")); | ||
} | ||
|
||
public void test32MaxMapBigEnough() throws Exception { | ||
// Ensures that if $MAX_MAP_COUNT is greater than the set | ||
// value on the OS we do not attempt to update it. | ||
sh.run("sysctl -q -w vm.max_map_count=262145"); | ||
startElasticsearch(); | ||
Shell.Result result = sh.run("sysctl -n vm.max_map_count"); | ||
String maxMapCount = result.stdout.strip(); | ||
sh.run("service elasticsearch stop"); | ||
assertThat(maxMapCount, equalTo("262145")); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It actually should be assumeFalse. This is necessary because some systems have both sysv init and systemd, where sysv commands are a thin layer over systemd. This assume is meant to ensure we only test on systems with true sysv init support. Without it the tests will fail as we are testing behavior specifically in our init.d script, which would not be run in the hybrid systems.