3434import java .util .Arrays ;
3535import java .util .List ;
3636import java .util .Optional ;
37+ import java .util .Set ;
3738import java .util .concurrent .CountDownLatch ;
3839import java .util .concurrent .ExecutorService ;
3940import java .util .concurrent .Executors ;
@@ -281,7 +282,8 @@ public void pushAllWait() throws Exception {
281282 plugin
282283 .getSysInjector ()
283284 .getInstance (PushAll .Factory .class )
284- .create (null , new ReplicationFilter (Arrays .asList (project .get ())), state , false )
285+ .create (
286+ null , Set .of (), new ReplicationFilter (Arrays .asList (project .get ())), state , false )
285287 .schedule (0 , TimeUnit .SECONDS );
286288
287289 future .get ();
@@ -301,7 +303,8 @@ public void pushAllWaitCancelNotRunningTask() throws Exception {
301303 plugin
302304 .getSysInjector ()
303305 .getInstance (PushAll .Factory .class )
304- .create (null , new ReplicationFilter (Arrays .asList (project .get ())), state , false )
306+ .create (
307+ null , Set .of (), new ReplicationFilter (Arrays .asList (project .get ())), state , false )
305308 .schedule (0 , TimeUnit .SECONDS );
306309
307310 CountDownLatch latch = new CountDownLatch (1 );
@@ -492,6 +495,51 @@ public void shouldReplicateWithPushBatchSizeSetForRemote() throws Exception {
492495 }
493496 }
494497
498+ @ Test
499+ public void shouldReplicateToMatchingRemote () throws Exception {
500+ Project .NameKey targetProject = createTestProject (project + "replica" );
501+
502+ setReplicationDestination ("foo" , "replica" , ALL_PROJECTS );
503+ reloadConfig ();
504+
505+ String newRef = "refs/heads/newForTest" ;
506+ ObjectId newRefTip = createNewBranchWithoutPush ("refs/heads/master" , newRef );
507+
508+ plugin
509+ .getSysInjector ()
510+ .getInstance (ReplicationQueue .class )
511+ .scheduleFullSync (project , null , Set .of ("foo" ), new ReplicationState (NO_OP ), true );
512+
513+ try (Repository repo = repoManager .openRepository (targetProject )) {
514+ waitUntil (() -> checkedGetRef (repo , newRef ) != null );
515+
516+ Ref targetBranchRef = getRef (repo , newRef );
517+ assertThat (targetBranchRef ).isNotNull ();
518+ assertThat (targetBranchRef .getObjectId ()).isEqualTo (newRefTip );
519+ }
520+ }
521+
522+ @ Test
523+ public void shouldNotReplicateToNonMatchingRemote () throws Exception {
524+ Project .NameKey targetProject = createTestProject (project + "replica" );
525+
526+ setReplicationDestination ("foo" , "replica" , ALL_PROJECTS );
527+ reloadConfig ();
528+
529+ String newRef = "refs/heads/newForTest" ;
530+ createNewBranchWithoutPush ("refs/heads/master" , newRef );
531+
532+ plugin
533+ .getSysInjector ()
534+ .getInstance (ReplicationQueue .class )
535+ .scheduleFullSync (project , null , Set .of ("bar" ), new ReplicationState (NO_OP ), true );
536+
537+ try (Repository repo = repoManager .openRepository (targetProject )) {
538+ assertThrows (
539+ InterruptedException .class , () -> waitUntil (() -> checkedGetRef (repo , newRef ) != null ));
540+ }
541+ }
542+
495543 private void waitUntil (Supplier <Boolean > waitCondition ) throws InterruptedException {
496544 WaitUtil .waitUntil (waitCondition , TEST_TIMEOUT );
497545 }
0 commit comments