• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SemaphoreStep类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep的典型用法代码示例。如果您正苦于以下问题:Java SemaphoreStep类的具体用法?Java SemaphoreStep怎么用?Java SemaphoreStep使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SemaphoreStep类属于org.jenkinsci.plugins.workflow.test.steps包,在下文中一共展示了SemaphoreStep类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: testDefaultJenkinsFile

import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test
public void testDefaultJenkinsFile() throws Exception {
    GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
    ConfigFileStore store = globalConfigFiles.get();

    Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
        "semaphore 'wait'; node {checkout scm; echo readFile('file')}");
    store.save(config);

    sampleGitRepo.init();
    sampleGitRepo.write("file", "initial content");
    sampleGitRepo.git("commit", "--all", "--message=flow");
    WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
    SemaphoreStep.waitForStart("wait/1", null);
    WorkflowRun b1 = p.getLastBuild();
    assertNotNull(b1);
    assertEquals(1, b1.getNumber());
    SemaphoreStep.success("wait/1", null);
    r.assertLogContains("initial content", r.waitForCompletion(b1));
}
 
开发者ID:vaimr,项目名称:pipeline-multibranch-defaults-plugin,代码行数:24,代码来源:DefaultsBinderTest.java


示例2: simple

import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test public void simple() {
    story.addStep(new Statement() {
        @Override public void evaluate() throws Throwable {
            WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
            p.setDefinition(new CpsFlowDefinition("waitUntil {semaphore 'wait'}; semaphore 'waited'", true));
            WorkflowRun b = p.scheduleBuild2(0).waitForStart();
            SemaphoreStep.waitForStart("wait/1", b);
            SemaphoreStep.success("wait/1", false);
            SemaphoreStep.waitForStart("wait/2", b);
            SemaphoreStep.success("wait/2", false);
            SemaphoreStep.waitForStart("wait/3", b);
            SemaphoreStep.success("wait/3", true);
            SemaphoreStep.waitForStart("waited/1", b);
            SemaphoreStep.success("waited/1", null);
            story.j.assertLogContains("Will try again after " + Util.getTimeSpanString(WaitForConditionStep.Execution.MIN_RECURRENCE_PERIOD), story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)));
        }
    });
}
 
开发者ID:10000TB,项目名称:Jenkins-Plugin-Examples,代码行数:19,代码来源:WaitForConditionStepTest.java


示例3: failure

import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test public void failure() {
    story.addStep(new Statement() {
        @Override public void evaluate() throws Throwable {
            WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
            p.setDefinition(new CpsFlowDefinition("waitUntil {semaphore 'wait'}", true));
            WorkflowRun b = p.scheduleBuild2(0).waitForStart();
            SemaphoreStep.waitForStart("wait/1", b);
            SemaphoreStep.success("wait/1", false);
            SemaphoreStep.waitForStart("wait/2", b);
            String message = "broken condition";
            SemaphoreStep.failure("wait/2", new AbortException(message));
            // TODO the following fails (missing message) when run as part of whole suite, but not standalone: story.j.assertLogContains(message, story.j.assertBuildStatus(Result.FAILURE, story.j.waitForCompletion(b)));
            story.j.waitForCompletion(b);
            story.j.assertBuildStatus(Result.FAILURE, b);
            story.j.assertLogContains(message, b); // TODO observed to flake on windows-8-2.32.3: see two `semaphore`s and a “Will try again after 0.25 sec” but no such message
        }
    });
}
 
开发者ID:10000TB,项目名称:Jenkins-Plugin-Examples,代码行数:19,代码来源:WaitForConditionStepTest.java


示例4: abortShouldNotRetry

import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Issue("JENKINS-41276")
@Test
public void abortShouldNotRetry() throws Exception {
    r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition(
            "int count = 0; retry(3) { echo 'trying '+(count++); semaphore 'start'; echo 'NotHere' } echo 'NotHere'", true));
    final WorkflowRun b = p.scheduleBuild2(0).waitForStart();
    SemaphoreStep.waitForStart("start/1", b);
    ACL.impersonate(User.get("dev").impersonate(), new Runnable() {
        @Override public void run() {
            b.getExecutor().doStop();
        }
    });
    r.assertBuildStatus(Result.ABORTED, r.waitForCompletion(b));
    r.assertLogContains("trying 0", b);
    r.assertLogContains("Aborted by dev", b);
    r.assertLogNotContains("trying 1", b);
    r.assertLogNotContains("trying 2", b);
    r.assertLogNotContains("NotHere", b);

}
 
开发者ID:10000TB,项目名称:Jenkins-Plugin-Examples,代码行数:23,代码来源:RetryStepTest.java


示例5: specialStatus

import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test public void specialStatus() throws Exception {
    User.get("smrt");
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition(
            "catchError {\n" +
            "  semaphore 'specialStatus'\n" +
            "}", true));
    SemaphoreStep.failure("specialStatus/1", new FlowInterruptedException(Result.UNSTABLE, new CauseOfInterruption.UserInterruption("smrt")));
    WorkflowRun b = p.scheduleBuild2(0).get();
    r.assertLogContains("smrt", r.assertBuildStatus(Result.UNSTABLE, b));
    /* TODO fixing this is trickier since CpsFlowExecution.setResult does not implement a public method, and anyway CatchErrorStep in its current location could not refer to FlowExecution:
    List<FlowNode> heads = b.getExecution().getCurrentHeads();
    assertEquals(1, heads.size());
    assertEquals(Result.UNSTABLE, ((FlowEndNode) heads.get(0)).getResult());
    */
}
 
开发者ID:10000TB,项目名称:Jenkins-Plugin-Examples,代码行数:17,代码来源:CatchErrorStepTest.java


示例6: parallel

import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test public void parallel() {
    story.addStep(new Statement() {
        @Override public void evaluate() throws Throwable {
            WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
            p.setDefinition(new CpsFlowDefinition(
                "parallel a: {\n" +
                "  node {withEnv(['TOOL=aloc']) {semaphore 'a'; isUnix() ? sh('echo TOOL=$TOOL') : bat('echo TOOL=%TOOL%')}}\n" +
                "}, b: {\n" +
                "  node {withEnv(['TOOL=bloc']) {semaphore 'b'; isUnix() ? sh('echo TOOL=$TOOL') : bat('echo TOOL=%TOOL%')}}\n" +
                "}", true));
            WorkflowRun b = p.scheduleBuild2(0).getStartCondition().get();
            SemaphoreStep.waitForStart("a/1", b);
            SemaphoreStep.waitForStart("b/1", b);
            SemaphoreStep.success("a/1", null);
            SemaphoreStep.success("b/1", null);
            story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b));
            story.j.assertLogContains("[a] TOOL=aloc", b);
            story.j.assertLogContains("[b] TOOL=bloc", b);
        }
    });
}
 
开发者ID:10000TB,项目名称:Jenkins-Plugin-Examples,代码行数:22,代码来源:EnvStepTest.java


示例7: smokes

import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Issue("JENKINS-26942")
@Test public void smokes() throws Exception {
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition(
        "node {\n" +
        "  writeFile file: 'subdir/fname', text: 'whatever'\n" +
        "  writeFile file: 'subdir/other', text: 'more'\n" +
        "  dir('subdir') {stash 'whatever'}\n" +
        "}\n" +
        "node {\n" +
        "  dir('elsewhere') {\n" +
        "    unstash 'whatever'\n" +
        "    echo \"got fname: ${readFile 'fname'} other: ${readFile 'other'}\"\n" +
        "  }\n" +
        "  writeFile file: 'at-top', text: 'ignored'\n" +
        "  stash name: 'from-top', includes: 'elsewhere/', excludes: '**/other'\n" +
        "  semaphore 'ending'\n" +
        "}", true));
    WorkflowRun b = p.scheduleBuild2(0).waitForStart();
    SemaphoreStep.waitForStart("ending/1", b);
    assertEquals("{from-top={elsewhere/fname=whatever}, whatever={fname=whatever, other=more}}", StashManager.stashesOf(b).toString());
    SemaphoreStep.success("ending/1", null);
    r.assertBuildStatusSuccess(r.waitForCompletion(b));
    r.assertLogContains("got fname: whatever other: more", b);
    assertEquals("{}", StashManager.stashesOf(b).toString()); // TODO flake expected:<{[]}> but was:<{[from-top={elsewhere/fname=whatever}, whatever={fname=whatever, other=more}]}>
}
 
开发者ID:10000TB,项目名称:Jenkins-Plugin-Examples,代码行数:27,代码来源:StashTest.java


示例8: testAllowEmpty

import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Issue("JENKINS-37327")
@Test public void testAllowEmpty() throws Exception {
    WorkflowJob p = r.jenkins.createProject(WorkflowJob.class, "p");
    p.setDefinition(new CpsFlowDefinition(
            "node {\n" +
                    "  stash name: 'whatever', allowEmpty: true\n" +
                    "  semaphore 'ending'\n" +
                    "}\n"
                    , true));
    WorkflowRun b = p.scheduleBuild2(0).waitForStart();
    SemaphoreStep.waitForStart("ending/1", b);
    assertEquals("{whatever={}}", StashManager.stashesOf(b).toString());
    SemaphoreStep.success("ending/1", null);
    r.assertBuildStatusSuccess(r.waitForCompletion(b));
    r.assertLogContains("Stashed 0 file(s)", b);
    assertEquals("{}", StashManager.stashesOf(b).toString());
    List<FlowNode> coreStepNodes = new DepthFirstScanner().filteredNodes(b.getExecution(), new NodeStepTypePredicate("stash"));
    assertThat(coreStepNodes, Matchers.hasSize(1));
    assertEquals("whatever", ArgumentsAction.getStepArgumentsAsString(coreStepNodes.get(0)));
}
 
开发者ID:10000TB,项目名称:Jenkins-Plugin-Examples,代码行数:21,代码来源:StashTest.java


示例9: testDefaultJenkinsFileLoadFromWorkspace

import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test
public void testDefaultJenkinsFileLoadFromWorkspace() throws Exception {
    GlobalConfigFiles globalConfigFiles = r.jenkins.getExtensionList(GlobalConfigFiles.class).get(GlobalConfigFiles.class);
    ConfigFileStore store = globalConfigFiles.get();
    Config config = new GroovyScript("Jenkinsfile", "Jenkinsfile", "",
        "semaphore 'wait'; node {checkout scm; load 'Jenkinsfile'}");
    store.save(config);


    sampleGitRepo.init();
    sampleGitRepo.write("Jenkinsfile", "echo readFile('file')");
    sampleGitRepo.git("add", "Jenkinsfile");
    sampleGitRepo.write("file", "initial content");
    sampleGitRepo.git("commit", "--all", "--message=flow");
    WorkflowMultiBranchProject mp = r.jenkins.createProject(PipelineMultiBranchDefaultsProject.class, "p");
    mp.getSourcesList().add(new BranchSource(new GitSCMSource(null, sampleGitRepo.toString(), "", "*", "", false),
        new DefaultBranchPropertyStrategy(new BranchProperty[0])));
    WorkflowJob p = PipelineMultiBranchDefaultsProjectTest.scheduleAndFindBranchProject(mp, "master");
    SemaphoreStep.waitForStart("wait/1", null);
    WorkflowRun b1 = p.getLastBuild();
    assertNotNull(b1);
    assertEquals(1, b1.getNumber());
    SemaphoreStep.success("wait/1", null);
    r.assertLogContains("initial content", r.waitForCompletion(b1));
}
 
开发者ID:vaimr,项目名称:pipeline-multibranch-defaults-plugin,代码行数:26,代码来源:DefaultsBinderTest.java


示例10: catchErrors

import org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep; //导入依赖的package包/类
@Test public void catchErrors() throws Exception {
    story.addStep(new Statement() {
        @Override public void evaluate() throws Throwable {
            WorkflowJob p = story.j.jenkins.createProject(WorkflowJob.class, "p");
            p.setDefinition(new CpsFlowDefinition(
                "node {\n" +
                "  waitUntil {\n" +
                "    try {\n" +
                "      readFile 'flag'\n" +
                "      true\n" +
                // Note that catching a specific type verifies JENKINS-26164:
                "    } catch (FileNotFoundException x) {\n" +
                "      // x.printStackTrace()\n" +
                "      semaphore 'wait'\n" +
                "      false\n" +
                "    }\n" +
                "  }\n" +
                "}\n" +
                "echo 'finished waiting'", true));
            WorkflowRun b = p.scheduleBuild2(0).waitForStart();
            SemaphoreStep.waitForStart("wait/1", b);
            story.j.jenkins.getWorkspaceFor(p).child("flag").write("", null);
            SemaphoreStep.success("wait/1", null);
            story.j.assertLogContains("finished waiting", story.j.assertBuildStatusSuccess(story.j.waitForCompletion(b)));
        }
    });
}
 
开发者ID:10000TB,项目名称:Jenkins-Plugin-Examples,代码行数:28,代码来源:WaitForConditionStepTest.java



注:本文中的org.jenkinsci.plugins.workflow.test.steps.SemaphoreStep类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Record类代码示例发布时间:2022-05-22
下一篇:
Java StepDefAnnotation类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap