Browse Source

UploadPackTest: Open TestRepository in try-with-resource

Change-Id: Id37a07b00584aa8a884fa11cd6f42a16b44e77f3
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
stable-5.4
David Pursehouse 6 years ago
parent
commit
43719e73c7
  1. 87
      org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java

87
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java

@ -200,8 +200,8 @@ public class UploadPackTest {
@Test @Test
public void testFetchWithBlobNoneFilter() throws Exception { public void testFetchWithBlobNoneFilter() throws Exception {
InMemoryRepository server2 = newRepo("server2"); InMemoryRepository server2 = newRepo("server2");
TestRepository<InMemoryRepository> remote2 = try (TestRepository<InMemoryRepository> remote2 = new TestRepository<>(
new TestRepository<>(server2); server2)) {
RevBlob blob1 = remote2.blob("foobar"); RevBlob blob1 = remote2.blob("foobar");
RevBlob blob2 = remote2.blob("fooba"); RevBlob blob2 = remote2.blob("fooba");
RevTree tree = remote2.tree(remote2.file("1", blob1), RevTree tree = remote2.tree(remote2.file("1", blob1),
@ -209,10 +209,10 @@ public class UploadPackTest {
RevCommit commit = remote2.commit(tree); RevCommit commit = remote2.commit(tree);
remote2.update("master", commit); remote2.update("master", commit);
server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true); server2.getConfig().setBoolean("uploadpack", null, "allowfilter",
true);
testProtocol = new TestProtocol<>( testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
new UploadPackFactory<Object>() {
@Override @Override
public UploadPack create(Object req, Repository db) public UploadPack create(Object req, Repository db)
throws ServiceNotEnabledException, throws ServiceNotEnabledException,
@ -232,12 +232,13 @@ public class UploadPackTest {
assertFalse(client.getObjectDatabase().has(blob2.toObjectId())); assertFalse(client.getObjectDatabase().has(blob2.toObjectId()));
} }
} }
}
@Test @Test
public void testFetchExplicitBlobWithFilter() throws Exception { public void testFetchExplicitBlobWithFilter() throws Exception {
InMemoryRepository server2 = newRepo("server2"); InMemoryRepository server2 = newRepo("server2");
TestRepository<InMemoryRepository> remote2 = try (TestRepository<InMemoryRepository> remote2 = new TestRepository<>(
new TestRepository<>(server2); server2)) {
RevBlob blob1 = remote2.blob("foobar"); RevBlob blob1 = remote2.blob("foobar");
RevBlob blob2 = remote2.blob("fooba"); RevBlob blob2 = remote2.blob("fooba");
RevTree tree = remote2.tree(remote2.file("1", blob1), RevTree tree = remote2.tree(remote2.file("1", blob1),
@ -246,10 +247,10 @@ public class UploadPackTest {
remote2.update("master", commit); remote2.update("master", commit);
remote2.update("a_blob", blob1); remote2.update("a_blob", blob1);
server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true); server2.getConfig().setBoolean("uploadpack", null, "allowfilter",
true);
testProtocol = new TestProtocol<>( testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
new UploadPackFactory<Object>() {
@Override @Override
public UploadPack create(Object req, Repository db) public UploadPack create(Object req, Repository db)
throws ServiceNotEnabledException, throws ServiceNotEnabledException,
@ -263,19 +264,19 @@ public class UploadPackTest {
try (Transport tn = testProtocol.open(uri, client, "server2")) { try (Transport tn = testProtocol.open(uri, client, "server2")) {
tn.setFilterBlobLimit(0); tn.setFilterBlobLimit(0);
tn.fetch(NullProgressMonitor.INSTANCE, Arrays.asList( tn.fetch(NullProgressMonitor.INSTANCE, Arrays.asList(
new RefSpec(commit.name()), new RefSpec(commit.name()), new RefSpec(blob1.name())));
new RefSpec(blob1.name())));
assertTrue(client.getObjectDatabase().has(tree.toObjectId())); assertTrue(client.getObjectDatabase().has(tree.toObjectId()));
assertTrue(client.getObjectDatabase().has(blob1.toObjectId())); assertTrue(client.getObjectDatabase().has(blob1.toObjectId()));
assertFalse(client.getObjectDatabase().has(blob2.toObjectId())); assertFalse(client.getObjectDatabase().has(blob2.toObjectId()));
} }
} }
}
@Test @Test
public void testFetchWithBlobLimitFilter() throws Exception { public void testFetchWithBlobLimitFilter() throws Exception {
InMemoryRepository server2 = newRepo("server2"); InMemoryRepository server2 = newRepo("server2");
TestRepository<InMemoryRepository> remote2 = try (TestRepository<InMemoryRepository> remote2 = new TestRepository<>(
new TestRepository<>(server2); server2)) {
RevBlob longBlob = remote2.blob("foobar"); RevBlob longBlob = remote2.blob("foobar");
RevBlob shortBlob = remote2.blob("fooba"); RevBlob shortBlob = remote2.blob("fooba");
RevTree tree = remote2.tree(remote2.file("1", longBlob), RevTree tree = remote2.tree(remote2.file("1", longBlob),
@ -283,10 +284,10 @@ public class UploadPackTest {
RevCommit commit = remote2.commit(tree); RevCommit commit = remote2.commit(tree);
remote2.update("master", commit); remote2.update("master", commit);
server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true); server2.getConfig().setBoolean("uploadpack", null, "allowfilter",
true);
testProtocol = new TestProtocol<>( testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
new UploadPackFactory<Object>() {
@Override @Override
public UploadPack create(Object req, Repository db) public UploadPack create(Object req, Repository db)
throws ServiceNotEnabledException, throws ServiceNotEnabledException,
@ -301,16 +302,19 @@ public class UploadPackTest {
tn.setFilterBlobLimit(5); tn.setFilterBlobLimit(5);
tn.fetch(NullProgressMonitor.INSTANCE, tn.fetch(NullProgressMonitor.INSTANCE,
Collections.singletonList(new RefSpec(commit.name()))); Collections.singletonList(new RefSpec(commit.name())));
assertFalse(client.getObjectDatabase().has(longBlob.toObjectId())); assertFalse(
assertTrue(client.getObjectDatabase().has(shortBlob.toObjectId())); client.getObjectDatabase().has(longBlob.toObjectId()));
assertTrue(
client.getObjectDatabase().has(shortBlob.toObjectId()));
}
} }
} }
@Test @Test
public void testFetchExplicitBlobWithFilterAndBitmaps() throws Exception { public void testFetchExplicitBlobWithFilterAndBitmaps() throws Exception {
InMemoryRepository server2 = newRepo("server2"); InMemoryRepository server2 = newRepo("server2");
TestRepository<InMemoryRepository> remote2 = try (TestRepository<InMemoryRepository> remote2 = new TestRepository<>(
new TestRepository<>(server2); server2)) {
RevBlob blob1 = remote2.blob("foobar"); RevBlob blob1 = remote2.blob("foobar");
RevBlob blob2 = remote2.blob("fooba"); RevBlob blob2 = remote2.blob("fooba");
RevTree tree = remote2.tree(remote2.file("1", blob1), RevTree tree = remote2.tree(remote2.file("1", blob1),
@ -319,14 +323,14 @@ public class UploadPackTest {
remote2.update("master", commit); remote2.update("master", commit);
remote2.update("a_blob", blob1); remote2.update("a_blob", blob1);
server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true); server2.getConfig().setBoolean("uploadpack", null, "allowfilter",
true);
// generate bitmaps // generate bitmaps
new DfsGarbageCollector(server2).pack(null); new DfsGarbageCollector(server2).pack(null);
server2.scanForRepoChanges(); server2.scanForRepoChanges();
testProtocol = new TestProtocol<>( testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
new UploadPackFactory<Object>() {
@Override @Override
public UploadPack create(Object req, Repository db) public UploadPack create(Object req, Repository db)
throws ServiceNotEnabledException, throws ServiceNotEnabledException,
@ -340,18 +344,18 @@ public class UploadPackTest {
try (Transport tn = testProtocol.open(uri, client, "server2")) { try (Transport tn = testProtocol.open(uri, client, "server2")) {
tn.setFilterBlobLimit(0); tn.setFilterBlobLimit(0);
tn.fetch(NullProgressMonitor.INSTANCE, Arrays.asList( tn.fetch(NullProgressMonitor.INSTANCE, Arrays.asList(
new RefSpec(commit.name()), new RefSpec(commit.name()), new RefSpec(blob1.name())));
new RefSpec(blob1.name())));
assertTrue(client.getObjectDatabase().has(blob1.toObjectId())); assertTrue(client.getObjectDatabase().has(blob1.toObjectId()));
assertFalse(client.getObjectDatabase().has(blob2.toObjectId())); assertFalse(client.getObjectDatabase().has(blob2.toObjectId()));
} }
} }
}
@Test @Test
public void testFetchWithBlobLimitFilterAndBitmaps() throws Exception { public void testFetchWithBlobLimitFilterAndBitmaps() throws Exception {
InMemoryRepository server2 = newRepo("server2"); InMemoryRepository server2 = newRepo("server2");
TestRepository<InMemoryRepository> remote2 = try (TestRepository<InMemoryRepository> remote2 = new TestRepository<>(
new TestRepository<>(server2); server2)) {
RevBlob longBlob = remote2.blob("foobar"); RevBlob longBlob = remote2.blob("foobar");
RevBlob shortBlob = remote2.blob("fooba"); RevBlob shortBlob = remote2.blob("fooba");
RevTree tree = remote2.tree(remote2.file("1", longBlob), RevTree tree = remote2.tree(remote2.file("1", longBlob),
@ -359,14 +363,14 @@ public class UploadPackTest {
RevCommit commit = remote2.commit(tree); RevCommit commit = remote2.commit(tree);
remote2.update("master", commit); remote2.update("master", commit);
server2.getConfig().setBoolean("uploadpack", null, "allowfilter", true); server2.getConfig().setBoolean("uploadpack", null, "allowfilter",
true);
// generate bitmaps // generate bitmaps
new DfsGarbageCollector(server2).pack(null); new DfsGarbageCollector(server2).pack(null);
server2.scanForRepoChanges(); server2.scanForRepoChanges();
testProtocol = new TestProtocol<>( testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
new UploadPackFactory<Object>() {
@Override @Override
public UploadPack create(Object req, Repository db) public UploadPack create(Object req, Repository db)
throws ServiceNotEnabledException, throws ServiceNotEnabledException,
@ -381,25 +385,28 @@ public class UploadPackTest {
tn.setFilterBlobLimit(5); tn.setFilterBlobLimit(5);
tn.fetch(NullProgressMonitor.INSTANCE, tn.fetch(NullProgressMonitor.INSTANCE,
Collections.singletonList(new RefSpec(commit.name()))); Collections.singletonList(new RefSpec(commit.name())));
assertFalse(client.getObjectDatabase().has(longBlob.toObjectId())); assertFalse(
assertTrue(client.getObjectDatabase().has(shortBlob.toObjectId())); client.getObjectDatabase().has(longBlob.toObjectId()));
assertTrue(
client.getObjectDatabase().has(shortBlob.toObjectId()));
}
} }
} }
@Test @Test
public void testFetchWithNonSupportingServer() throws Exception { public void testFetchWithNonSupportingServer() throws Exception {
InMemoryRepository server2 = newRepo("server2"); InMemoryRepository server2 = newRepo("server2");
TestRepository<InMemoryRepository> remote2 = try (TestRepository<InMemoryRepository> remote2 = new TestRepository<>(
new TestRepository<>(server2); server2)) {
RevBlob blob = remote2.blob("foo"); RevBlob blob = remote2.blob("foo");
RevTree tree = remote2.tree(remote2.file("1", blob)); RevTree tree = remote2.tree(remote2.file("1", blob));
RevCommit commit = remote2.commit(tree); RevCommit commit = remote2.commit(tree);
remote2.update("master", commit); remote2.update("master", commit);
server2.getConfig().setBoolean("uploadpack", null, "allowfilter", false); server2.getConfig().setBoolean("uploadpack", null, "allowfilter",
false);
testProtocol = new TestProtocol<>( testProtocol = new TestProtocol<>(new UploadPackFactory<Object>() {
new UploadPackFactory<Object>() {
@Override @Override
public UploadPack create(Object req, Repository db) public UploadPack create(Object req, Repository db)
throws ServiceNotEnabledException, throws ServiceNotEnabledException,
@ -414,12 +421,14 @@ public class UploadPackTest {
tn.setFilterBlobLimit(0); tn.setFilterBlobLimit(0);
thrown.expect(TransportException.class); thrown.expect(TransportException.class);
thrown.expectMessage("filter requires server to advertise that capability"); thrown.expectMessage(
"filter requires server to advertise that capability");
tn.fetch(NullProgressMonitor.INSTANCE, tn.fetch(NullProgressMonitor.INSTANCE,
Collections.singletonList(new RefSpec(commit.name()))); Collections.singletonList(new RefSpec(commit.name())));
} }
} }
}
/* /*
* Invokes UploadPack with protocol v2 and sends it the given lines, * Invokes UploadPack with protocol v2 and sends it the given lines,

Loading…
Cancel
Save