Search in sources :

Example 1 with ActiveMQSubscriberProviderData

use of com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData in project jms-messaging-plugin by jenkinsci.

the class MigrationTest method testConfig.

@LocalData
@Test
public void testConfig() {
    assertEquals("config is not 1", 1, GlobalCIConfiguration.get().getConfigs().size());
    JMSMessagingProvider config = GlobalCIConfiguration.get().getConfigs().get(0);
    ActiveMqMessagingProvider aconfig = (ActiveMqMessagingProvider) config;
    String topic = aconfig.getTopic();
    assertEquals("topic is not TOM", "TOM", topic);
    AbstractProject<?, ?> triggerJob = (AbstractProject<?, ?>) j.getInstance().getItem("ci-trigger");
    CIBuildTrigger trigger = triggerJob.getTrigger(CIBuildTrigger.class);
    assertNotNull(trigger);
    CIBuildTrigger cibt = triggerJob.getTrigger(CIBuildTrigger.class);
    assertTrue(cibt.getProviders().get(0) instanceof ActiveMQSubscriberProviderData);
    assertNotNull(cibt.getProviders().get(0).getName());
    assertNotNull(cibt.getSelector());
    FreeStyleProject notifierJob = (FreeStyleProject) j.getInstance().getItem("ci-notifier");
    CIMessageBuilder builder = notifierJob.getBuildersList().get(CIMessageBuilder.class);
    assertNotNull(builder);
    assertNotNull(builder.getProviderName());
    assertNotNull(notifierJob.getPublishersList());
    CIMessageNotifier notifierPublisher = notifierJob.getPublishersList().get(CIMessageNotifier.class);
    assertNotNull(notifierPublisher.getProviderName());
    FreeStyleProject subscriberJob = (FreeStyleProject) j.getInstance().getItem("ci-message-subscriber");
    CIMessageSubscriberBuilder subscriberBuilder = subscriberJob.getBuildersList().get(CIMessageSubscriberBuilder.class);
    assertNotNull(subscriberBuilder);
    assertNotNull(subscriberBuilder.getProviderName());
    GlobalCIConfiguration newGlobalConfig = new GlobalCIConfiguration();
    JMSMessagingProvider config2 = newGlobalConfig.getConfigs().get(0);
    ActiveMqMessagingProvider aconfig2 = (ActiveMqMessagingProvider) config2;
    assertNotNull(aconfig2.getAuthenticationMethod());
}
Also used : ActiveMqMessagingProvider(com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingProvider) ActiveMQSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData) JMSMessagingProvider(com.redhat.jenkins.plugins.ci.messaging.JMSMessagingProvider) AbstractProject(hudson.model.AbstractProject) FreeStyleProject(hudson.model.FreeStyleProject) LocalData(org.jvnet.hudson.test.recipes.LocalData) Test(org.junit.Test)

Example 2 with ActiveMQSubscriberProviderData

use of com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData in project jms-messaging-plugin by jenkinsci.

the class AmqMessagingPluginWithFailoverIntegrationTest method testSimpleCIEventTrigger.

@Test
public void testSimpleCIEventTrigger() throws Exception {
    ArrayList<FreeStyleProject> jobs = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        FreeStyleProject jobA = j.createFreeStyleProject("receiver" + i);
        jobA.getBuildersList().add(new Shell("echo CI_TYPE = $CI_TYPE"));
        jobA.addTrigger(new CIBuildTrigger(true, Collections.singletonList(new ActiveMQSubscriberProviderData(SharedMessagingPluginIntegrationTest.DEFAULT_PROVIDER_NAME, null, "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'failed'", Collections.emptyList(), "CI_MESSAGE", 60))));
    }
    waitForNoAMQTaskThreads();
    long currentThreadCount = getCurrentAMQThreadCount();
    System.out.println("Current AMQ Thread Count: " + currentThreadCount);
    String previousThreads = printAMQThreads();
    System.out.println(previousThreads);
    FreeStyleProject jobB = j.createFreeStyleProject("sender");
    jobB.getPublishersList().add(new CIMessageNotifier(new ActiveMQPublisherProviderData(SharedMessagingPluginIntegrationTest.DEFAULT_PROVIDER_NAME, null, MessageUtils.MESSAGE_TYPE.CodeQualityChecksDone, "CI_STATUS = failed", null, true)));
    j.buildAndAssertSuccess(jobB);
    for (FreeStyleProject job : jobs) {
        FreeStyleBuild lastBuild = job.getLastBuild();
        j.assertBuildStatusSuccess(lastBuild);
        j.assertLogContains("echo CI_TYPE = code-quality-checks-done", lastBuild);
        lastBuild.delete();
    }
    // Now stop AMQ
    System.out.println("Stopping AMQ");
    stopAMQ();
    System.out.println("Waiting 60 secs");
    Thread.sleep(60000);
    // Check for unconnection AMQ threads
    System.out.println(printAMQThreads());
    ensureNoUnconnectedThreads();
    // Now startup
    System.out.println("Starting AMQ");
    startAMQ();
    System.out.println("Waiting 10 secs");
    Thread.sleep(10000);
    waitForNoAMQTaskThreads();
    System.out.println(printAMQThreads());
    ensureNoLeakingThreads(currentThreadCount, previousThreads);
    j.buildAndAssertSuccess(jobB);
    Thread.sleep(1000);
    for (FreeStyleProject job : jobs) {
        FreeStyleBuild lastBuild = job.getLastBuild();
        j.assertBuildStatusSuccess(lastBuild);
        j.assertLogContains("echo CI_TYPE = code-quality-checks-done", lastBuild);
        lastBuild.delete();
    }
    System.out.println(printAMQThreads());
    System.out.println("Waiting 10 secs");
    Thread.sleep(10000);
    waitForNoAMQTaskThreads();
}
Also used : Shell(hudson.tasks.Shell) ActiveMQSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData) CIMessageNotifier(com.redhat.jenkins.plugins.ci.CIMessageNotifier) ActiveMQPublisherProviderData(com.redhat.jenkins.plugins.ci.provider.data.ActiveMQPublisherProviderData) ArrayList(java.util.ArrayList) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 3 with ActiveMQSubscriberProviderData

use of com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData in project jms-messaging-plugin by jenkinsci.

the class AmqMessagingPluginWithFailoverIntegrationTest method testInvalidJMSSelector.

// Test setting a valid JMS selector, then fixing it, and make sure threads are handled correctly.
@Test
public void testInvalidJMSSelector() throws Exception {
    FreeStyleProject jobA = j.createFreeStyleProject("receiver");
    jobA.getBuildersList().add(new Shell("echo CI_TYPE = $CI_TYPE"));
    jobA.addTrigger(new CIBuildTrigger(true, Collections.singletonList(new ActiveMQSubscriberProviderData(SharedMessagingPluginIntegrationTest.DEFAULT_PROVIDER_NAME, null, // Missing '='; invalid syntax.
    "CI_TYPE 'code-quality-checks-done' and CI_STATUS = 'failed'", Collections.emptyList(), "CI_MESSAGE", 60))));
    jobA.getTrigger(CIBuildTrigger.class).start(jobA, true);
    // Wait for connection to fail
    Thread.sleep(5000);
    List<Long> ids1 = getCurrentTriggerThreadIds("receiver");
    assertEquals("Trigger threads invalid size", 0, ids1.size());
    JenkinsRule.WebClient wc = j.createWebClient();
    String source = wc.getPage(jobA).getWebResponse().getContentAsString();
    assertThat(source, containsString("CI Build Trigger Issue"));
    assertThat(source, containsString("javax.jms.InvalidSelectorException"));
    // Now fix the selector.
    jobA.addTrigger(new CIBuildTrigger(true, Collections.singletonList(new ActiveMQSubscriberProviderData(SharedMessagingPluginIntegrationTest.DEFAULT_PROVIDER_NAME, null, "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'failed'", Collections.emptyList(), "CI_MESSAGE", 60))));
    new CIBuildTrigger(true, Collections.singletonList(new ActiveMQSubscriberProviderData(SharedMessagingPluginIntegrationTest.DEFAULT_PROVIDER_NAME, null, // Missing '='; invalid syntax.
    "CI_TYPE 'code-quality-checks-done' and CI_STATUS = 'failed'", Collections.emptyList(), "CI_MESSAGE", 60))).start(jobA, true);
    List<Long> ids2 = getCurrentTriggerThreadIds("receiver");
    assertEquals("Trigger threads valid selector size", 1, ids2.size());
}
Also used : Shell(hudson.tasks.Shell) ActiveMQSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 4 with ActiveMQSubscriberProviderData

use of com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData in project jms-messaging-plugin by jenkinsci.

the class MessageProviderMigrator method updateCIMessageSubscriberBuilder.

private static boolean updateCIMessageSubscriberBuilder(AbstractProject<?, ?> p, CIMessageSubscriberBuilder builder) {
    if (builder.getProviderData() == null) {
        if (builder.getProviderName() == null) {
            builder.setProviderName(GlobalCIConfiguration.get().getConfigs().get(0).getName());
        }
        JMSMessagingProvider prov = GlobalCIConfiguration.get().getProvider(builder.getProviderName());
        if (prov instanceof ActiveMqMessagingProvider) {
            ActiveMQSubscriberProviderData apd = new ActiveMQSubscriberProviderData(builder.getProviderName());
            apd.setOverrides(builder.getOverrides());
            apd.setSelector(builder.getSelector());
            apd.setChecks(builder.getChecks());
            apd.setVariable(builder.getVariable());
            apd.setTimeout(builder.getTimeout());
            builder.setProviderData(apd);
        } else if (prov instanceof FedMsgMessagingProvider) {
            FedMsgSubscriberProviderData fpd = new FedMsgSubscriberProviderData(builder.getProviderName());
            fpd.setOverrides(builder.getOverrides());
            fpd.setVariable(builder.getVariable());
            fpd.setTimeout(builder.getTimeout());
            builder.setProviderData(fpd);
        } else {
            RabbitMQSubscriberProviderData rpd = new RabbitMQSubscriberProviderData(builder.getProviderName());
            rpd.setOverrides(builder.getOverrides());
            rpd.setVariable(builder.getVariable());
            rpd.setTimeout(builder.getTimeout());
            builder.setProviderData(rpd);
        }
        try {
            p.save();
            return true;
        } catch (IOException e) {
            log.log(Level.WARNING, "Failed to save project", e);
        }
    }
    return false;
}
Also used : FedMsgSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.FedMsgSubscriberProviderData) ActiveMQSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData) RabbitMQSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.RabbitMQSubscriberProviderData) IOException(java.io.IOException)

Example 5 with ActiveMQSubscriberProviderData

use of com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData in project jms-messaging-plugin by jenkinsci.

the class AmqMessagingPluginWithFailoverIntegrationTest method testChangingJMSSelector.

@Test
public void testChangingJMSSelector() throws Exception {
    // Test changing a selector and make sure threads are handled correctly.
    FreeStyleProject jobA = j.createFreeStyleProject("receiver");
    jobA.getBuildersList().add(new Shell("echo CI_TYPE = $CI_TYPE"));
    jobA.addTrigger(new CIBuildTrigger(true, Collections.singletonList(new ActiveMQSubscriberProviderData(SharedMessagingPluginIntegrationTest.DEFAULT_PROVIDER_NAME, null, "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'failed'", Collections.emptyList(), "CI_MESSAGE", 60))));
    jobA.getTrigger(CIBuildTrigger.class).start(jobA, true);
    List<Long> ids1 = getCurrentTriggerThreadIds("receiver");
    assertEquals("Trigger threads value selector size", 1, ids1.size());
    // Now change the selector.
    jobA.getTrigger(CIBuildTrigger.class).setProviderList(Collections.singletonList(new ActiveMQSubscriberProviderData(SharedMessagingPluginIntegrationTest.DEFAULT_PROVIDER_NAME, null, "CI_TYPE = 'code-quality-checks-done' and CI_STATUS = 'success'", Collections.emptyList(), "CI_MESSAGE", 60)));
    jobA.getTrigger(CIBuildTrigger.class).start(jobA, true);
    List<Long> ids2 = getCurrentTriggerThreadIds("receiver");
    assertEquals("Trigger threads changed selector size", 1, ids2.size());
    assertNotSame("Trigger threads new thread created", ids1.get(0), ids2.get(0));
}
Also used : Shell(hudson.tasks.Shell) ActiveMQSubscriberProviderData(com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData) CIBuildTrigger(com.redhat.jenkins.plugins.ci.CIBuildTrigger) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Aggregations

ActiveMQSubscriberProviderData (com.redhat.jenkins.plugins.ci.provider.data.ActiveMQSubscriberProviderData)8 FreeStyleProject (hudson.model.FreeStyleProject)4 Test (org.junit.Test)4 CIBuildTrigger (com.redhat.jenkins.plugins.ci.CIBuildTrigger)3 Shell (hudson.tasks.Shell)3 ActiveMqMessagingProvider (com.redhat.jenkins.plugins.ci.messaging.ActiveMqMessagingProvider)2 JMSMessagingProvider (com.redhat.jenkins.plugins.ci.messaging.JMSMessagingProvider)2 FedMsgSubscriberProviderData (com.redhat.jenkins.plugins.ci.provider.data.FedMsgSubscriberProviderData)2 IOException (java.io.IOException)2 BytesMessage (javax.jms.BytesMessage)2 JMSException (javax.jms.JMSException)2 MapMessage (javax.jms.MapMessage)2 Message (javax.jms.Message)2 TextMessage (javax.jms.TextMessage)2 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 CIEnvironmentContributingAction (com.redhat.jenkins.plugins.ci.CIEnvironmentContributingAction)1 CIMessageNotifier (com.redhat.jenkins.plugins.ci.CIMessageNotifier)1 FedMsgMessagingProvider (com.redhat.jenkins.plugins.ci.messaging.FedMsgMessagingProvider)1 ActiveMQPublisherProviderData (com.redhat.jenkins.plugins.ci.provider.data.ActiveMQPublisherProviderData)1 RabbitMQSubscriberProviderData (com.redhat.jenkins.plugins.ci.provider.data.RabbitMQSubscriberProviderData)1