@Test void testSingleTypeMirror() { metaRepo.commit(Revision.HEAD, 0, Author.SYSTEM, "", Change.ofJsonUpsert( PATH_MIRRORS, "[{" + " \"enabled\": true," + " \"type\": \"single\"," + " \"direction\": \"LOCAL_TO_REMOTE\"," + " \"localRepo\": \"foo\"," + " \"localPath\": \"/mirrors/foo\"," + " \"remoteUri\": \"git+ssh: "},{" + " \"enabled\": true," + " \"type\": \"single\"," + " \"schedule\": \"*/10 * * * * ?\"," + " \"direction\": \"REMOTE_TO_LOCAL\"," + " \"localRepo\": \"bar\"," + " \"remoteUri\": \"git+ssh: "}, {" + " \"type\": \"single\"," + " \"direction\": \"LOCAL_TO_REMOTE\"," + " \"localRepo\": \"qux\"," + " \"remoteUri\": \"git+ssh: "}, {" + " \"enabled\": false," + " \"type\": \"single\"," + " \"direction\": \"LOCAL_TO_REMOTE\"," + " \"localRepo\": \"foo\"," + " \"localPath\": \"/mirrors/bar\"," + " \"remoteUri\": \"git+ssh: "}]"), UPSERT_CREDENTIALS).join(); assertThat(metaRepo.mirrors()).isEmpty(); project.repos().create("foo", Author.SYSTEM); project.repos().create("bar", Author.SYSTEM); project.repos().create("qux", Author.SYSTEM); final List<Mirror> mirrors = findMirrors(); assertThat(mirrors.stream() .map(m -> m.localRepo().name()) .collect(Collectors.toList())).containsExactly("bar", "foo", "qux"); final Mirror foo = mirrors.get(1); final Mirror bar = mirrors.get(0); final Mirror qux = mirrors.get(2); assertThat(foo.direction()).isEqualTo(MirrorDirection.LOCAL_TO_REMOTE); assertThat(bar.direction()).isEqualTo(MirrorDirection.REMOTE_TO_LOCAL); assertThat(qux.direction()).isEqualTo(MirrorDirection.LOCAL_TO_REMOTE); assertThat(foo.schedule().equivalent(cronParser.parse("0 * * * * ?"))).isTrue(); assertThat(bar.schedule().equivalent(cronParser.parse("*/10 * * * * ?"))).isTrue(); assertThat(qux.schedule().equivalent(cronParser.parse("0 * * * * ?"))).isTrue(); assertThat(foo.localPath()).isEqualTo("/mirrors/foo/"); assertThat(bar.localPath()).isEqualTo("/"); assertThat(qux.localPath()).isEqualTo("/"); assertThat(foo.remoteRepoUri().toString()).isEqualTo("git+ssh: assertThat(bar.remoteRepoUri().toString()).isEqualTo("git+ssh: assertThat(qux.remoteRepoUri().toString()).isEqualTo("git+ssh: assertThat(foo.remotePath()).isEqualTo("/"); assertThat(bar.remotePath()).isEqualTo("/some-path/"); assertThat(qux.remotePath()).isEqualTo("/"); assertThat(foo.remoteBranch()).isEqualTo("master"); assertThat(bar.remoteBranch()).isEqualTo("master"); assertThat(qux.remoteBranch()).isEqualTo("develop"); assertThat(foo.credential()).isInstanceOf(PasswordMirrorCredential.class); assertThat(bar.credential()).isInstanceOf(PasswordMirrorCredential.class); assertThat(qux.credential()).isInstanceOf(NoneMirrorCredential.class); final PasswordMirrorCredential fooCredential = (PasswordMirrorCredential) foo.credential(); final PasswordMirrorCredential barCredential = (PasswordMirrorCredential) bar.credential(); assertThat(fooCredential.username()).isEqualTo("alice"); assertThat(fooCredential.password()).isEqualTo("secret_a"); assertThat(barCredential.username()).isEqualTo("bob"); assertThat(barCredential.password()).isEqualTo("secret_b"); }
@Override public Set<Mirror> mirrors() { mirrorLock.lock(); try { final int headRev = normalizeNow(Revision.HEAD).major(); final Set<String> repos = parent().repos().list().keySet(); if (headRev > mirrorRev || !mirrorRepos.equals(repos)) { mirrors = loadMirrors(headRev); mirrorRev = headRev; mirrorRepos = repos; } return mirrors; } finally { mirrorLock.unlock(); } }
DefaultMetaRepository extends RepositoryWrapper implements MetaRepository { @Override public Set<Mirror> mirrors() { mirrorLock.lock(); try { final int headRev = normalizeNow(Revision.HEAD).major(); final Set<String> repos = parent().repos().list().keySet(); if (headRev > mirrorRev || !mirrorRepos.equals(repos)) { mirrors = loadMirrors(headRev); mirrorRev = headRev; mirrorRepos = repos; } return mirrors; } finally { mirrorLock.unlock(); } } }
DefaultMetaRepository extends RepositoryWrapper implements MetaRepository { @Override public Set<Mirror> mirrors() { mirrorLock.lock(); try { final int headRev = normalizeNow(Revision.HEAD).major(); final Set<String> repos = parent().repos().list().keySet(); if (headRev > mirrorRev || !mirrorRepos.equals(repos)) { mirrors = loadMirrors(headRev); mirrorRev = headRev; mirrorRepos = repos; } return mirrors; } finally { mirrorLock.unlock(); } } DefaultMetaRepository(Repository repo); }
DefaultMetaRepository extends RepositoryWrapper implements MetaRepository { @Override public Set<Mirror> mirrors() { mirrorLock.lock(); try { final int headRev = normalizeNow(Revision.HEAD).major(); final Set<String> repos = parent().repos().list().keySet(); if (headRev > mirrorRev || !mirrorRepos.equals(repos)) { mirrors = loadMirrors(headRev); mirrorRev = headRev; mirrorRepos = repos; } return mirrors; } finally { mirrorLock.unlock(); } } DefaultMetaRepository(Repository repo); @Override Set<Mirror> mirrors(); }
DefaultMetaRepository extends RepositoryWrapper implements MetaRepository { @Override public Set<Mirror> mirrors() { mirrorLock.lock(); try { final int headRev = normalizeNow(Revision.HEAD).major(); final Set<String> repos = parent().repos().list().keySet(); if (headRev > mirrorRev || !mirrorRepos.equals(repos)) { mirrors = loadMirrors(headRev); mirrorRev = headRev; mirrorRepos = repos; } return mirrors; } finally { mirrorLock.unlock(); } } DefaultMetaRepository(Repository repo); @Override Set<Mirror> mirrors();  }