Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[JENKINS-14806] Updated test and added multisite polling variable to …
…the scm class
  • Loading branch information
wolfgarnet committed Aug 17, 2012
1 parent b4282c3 commit 9cf068a
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 22 deletions.
16 changes: 13 additions & 3 deletions src/main/java/net/praqma/hudson/scm/CCUCMScm.java
Expand Up @@ -94,6 +94,9 @@
* information can be entered on the config page.
*/
public class CCUCMScm extends SCM {

/* Currently only for testing */
private Boolean multisitePolling;

private Project.PromotionLevel plevel;
private String levelToPoll;
Expand Down Expand Up @@ -1319,9 +1322,12 @@ public boolean getSlavePolling() {
}

public boolean getMultisitePolling() {
CCUCMScmDescriptor desc = (CCUCMScmDescriptor) this.getDescriptor();
return desc.getMultisitePolling();

if( this.multisitePolling != null ) {
return this.multisitePolling;
} else {
CCUCMScmDescriptor desc = (CCUCMScmDescriptor) this.getDescriptor();
return desc.getMultisitePolling();
}
}

@Exported
Expand Down Expand Up @@ -1370,6 +1376,10 @@ public boolean isRecommend() {
public Appender getAppender() {
return app;
}

public void setMultisitePolling( boolean mp ) {
this.multisitePolling = mp;
}

/**
* This class is used to describe the plugin to Hudson
Expand Down
@@ -1,28 +1,30 @@
package net.praqma.hudson.test.integration.userstories;

import java.io.IOException;
import java.util.concurrent.Future;

import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.modules.junit4.PowerMockRunner;
import org.jvnet.hudson.test.TestBuilder;

import hudson.Launcher;
import hudson.model.AbstractBuild;
import hudson.model.AbstractProject;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import net.praqma.clearcase.ucm.entities.Baseline;
import net.praqma.clearcase.ucm.entities.Project.PromotionLevel;
import hudson.model.BuildListener;
import hudson.model.FreeStyleBuild;
import hudson.scm.PollingResult;
import net.praqma.hudson.scm.CCUCMScm;
import net.praqma.hudson.test.CCUCMRule;
import net.praqma.hudson.test.SystemValidator;
import net.praqma.junit.DescriptionRule;
import net.praqma.junit.TestDescription;

import net.praqma.clearcase.test.junit.ClearCaseRule;

@RunWith( PowerMockRunner.class )
import static org.junit.Assert.*;

import static org.hamcrest.CoreMatchers.*;

public class JENKINS14806 {

@ClassRule
Expand All @@ -39,17 +41,52 @@ public class JENKINS14806 {
public void jenkins13944() throws Exception {

CCUCMScm ccucm = jenkins.getCCUCM( "child", "_System@" + ccenv.getPVob(), "one_int@" + ccenv.getPVob(), "INITIAL", false, false, false, false, true, "[project]_[date]_[time]" );
CCUCMScm ccucmspy = Mockito.spy( ccucm );
ccucm.setMultisitePolling( true );
System.out.println( "MP: " + ccucm.getMultisitePolling() );
FreeStyleProject project = jenkins.createProject( ccenv.getUniqueName(), ccucm );

/* First build to create a view */
System.out.println( "First build" );
jenkins.buildProject( project, false );

/* Behaviour */
PowerMockito.doReturn( true ).when( ccucmspy ).getMultisitePolling();
/* Add builder to sleep */
System.out.println( "Adding waiter" );
project.getBuildersList().add( new WaitBuilder( 10000 ) );

FreeStyleProject project = jenkins.createProject( ccenv.getUniqueName(), ccucmspy );
System.out.println( "Async build" );
Future<FreeStyleBuild> futureBuild = project.scheduleBuild2( 0 );

/* Remove the builder again */
System.out.println( "Clear builders" );
project.getBuildersList().clear();

/* And then poll */
System.out.println( "Poll" );
PollingResult result = project.poll( jenkins.createTaskListener() );

System.out.println( "Assert" );
assertThat( result, is( PollingResult.NO_CHANGES ) );

System.out.println( "Waiting for waiter" );
futureBuild.get();
}

public class WaitBuilder extends TestBuilder {

int millisecs;

public WaitBuilder( int ms ) {
this.millisecs = ms;
}

@Override
public boolean perform( AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener ) throws InterruptedException, IOException {
System.out.println( "Sleeping...." );
Thread.sleep( this.millisecs );
System.out.println( "Awaken...." );
return true;
}

/* First build to create a view */
AbstractBuild<?, ?> build = jenkins.buildProject( project, false );
Baseline baseline = ccenv.context.baselines.get( "model-1" );
new SystemValidator( build ).validateBuild( Result.SUCCESS ).validateBuiltBaseline( PromotionLevel.BUILT, baseline, false ).validate();
}


Expand Down
2 changes: 1 addition & 1 deletion src/test/resources/setup-JENKINS-14806.xml
Expand Up @@ -6,7 +6,7 @@

<context mvfs="m:\" linux="/view" view="${name}_one_dev" vob="${vobname}"/>

<activity comment="" headline="Adding initial files into components" in="one_int" name="initial_files" pvob="${pvobname}" />
<activity comment="" headline="Adding initial files into components" in="one_dev" name="initial_files" pvob="${pvobname}" />

<setactivity activity="initial_files" pvob="${pvobname}" />

Expand Down

0 comments on commit 9cf068a

Please sign in to comment.