public virtual void TestMaxObjectSizeDeltaResultSize() { TestRepository d = new TestRepository <FileRepository>(db); RevBlob a = d.Blob("0123456789"); TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 1); pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4); a.CopyRawTo(pack); Deflate(pack, new byte[] { 10, 11, 1, (byte)('a') }); Digest(pack); PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(true); p.SetMaxObjectSizeLimit(11); p.Parse(NullProgressMonitor.INSTANCE); p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(true); p.SetMaxObjectSizeLimit(10); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("PackParser should have failed"); } catch (TooLargeObjectInPackException e) { NUnit.Framework.Assert.IsTrue(e.Message.Contains("11")); // result obj size NUnit.Framework.Assert.IsTrue(e.Message.Contains("10")); } }
public override void SetUp() { base.SetUp(); src = CreateBareRepository(); dst = CreateBareRepository(); // Fill dst with a some common history. // TestRepository d = new TestRepository <Repository>(dst); a = d.Blob("a"); A = d.Commit(d.Tree(d.File("a", a))); B = d.Commit().Parent(A).Create(); d.Update(R_MASTER, B); // Clone from dst into src // NGit.Transport.Transport t = NGit.Transport.Transport.Open(src, UriOf(dst)); try { t.Fetch(PM, Collections.Singleton(new RefSpec("+refs/*:refs/*"))); NUnit.Framework.Assert.AreEqual(B, src.Resolve(R_MASTER)); } finally { t.Close(); } // Now put private stuff into dst. // b = d.Blob("b"); P = d.Commit(d.Tree(d.File("b", b)), A); d.Update(R_PRIVATE, P); }
public virtual void TestDataAfterPackFooterSplitHeaderRead() { TestRepository d = new TestRepository <FileRepository>(db); byte[] data = Constants.Encode("a"); RevBlob b = d.Blob(data); int objects = 248; TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(32 * 1024); PackHeader(pack, objects + 1); int offset = 13; StringBuilder sb = new StringBuilder(); for (int i = 0; i < offset; i++) { sb.Append(i); } offset = sb.ToString().Length; int lenByte = (Constants.OBJ_BLOB) << 4 | (offset & unchecked ((int)(0x0F))); offset >>= 4; if (offset > 0) { lenByte |= 1 << 7; } pack.Write(lenByte); while (offset > 0) { lenByte = offset & unchecked ((int)(0x7F)); offset >>= 6; if (offset > 0) { lenByte |= 1 << 7; } pack.Write(lenByte); } Deflate(pack, Constants.Encode(sb.ToString())); for (int i_1 = 0; i_1 < objects; i_1++) { // The last pack header written falls across the 8192 byte boundary // between [8189:8210] pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4); b.CopyRawTo(pack); Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('b') }); } Digest(pack); byte[] packData = pack.ToByteArray(); byte[] streamData = new byte[packData.Length + 1]; System.Array.Copy(packData, 0, streamData, 0, packData.Length); streamData[packData.Length] = unchecked ((int)(0x7e)); InputStream @in = new ByteArrayInputStream(streamData); PackParser p = Index(@in); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(false); p.SetExpectDataAfterPackFooter(true); p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x7e)), @in.Read()); }
public virtual void TestNonMarkingInputStream() { TestRepository d = new TestRepository <FileRepository>(db); RevBlob a = d.Blob("a"); TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 1); pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4); a.CopyRawTo(pack); Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('b') }); Digest(pack); InputStream @in = new _ByteArrayInputStream_319(pack.ToByteArray()); PackParser p = Index(@in); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(false); p.SetExpectDataAfterPackFooter(true); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("PackParser should have failed"); } catch (IOException e) { NUnit.Framework.Assert.AreEqual(e.Message, JGitText.Get().inputStreamMustSupportMark ); } }
public virtual void TestDataAfterPackFooterSingleRead() { TestRepository d = new TestRepository <FileRepository>(db); RevBlob a = d.Blob("a"); TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(32 * 1024); PackHeader(pack, 1); pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4); a.CopyRawTo(pack); Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('b') }); Digest(pack); byte[] packData = pack.ToByteArray(); byte[] streamData = new byte[packData.Length + 1]; System.Array.Copy(packData, 0, streamData, 0, packData.Length); streamData[packData.Length] = unchecked ((int)(0x7e)); InputStream @in = new ByteArrayInputStream(streamData); PackParser p = Index(@in); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(false); p.SetExpectDataAfterPackFooter(true); p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x7e)), @in.Read()); }
public void testTwoCommitDeepTree2() { RevBlob f1 = blob("1"); RevTree ta = tree(File("a/b/0", f1), File("a/c/q", f1)); RevTree tb = tree(File("a/b/1", f1), File("a/c/q", f1)); RevCommit a = Commit(ta); RevCommit b = Commit(tb, a); MarkStart(b); AssertCommit(b, objw.next()); AssertCommit(a, objw.next()); Assert.IsNull(objw.next()); Assert.AreSame(tb, objw.nextObject()); Assert.AreSame(get(tb, "a"), objw.nextObject()); Assert.AreSame(get(tb, "a/b"), objw.nextObject()); Assert.AreSame(f1, objw.nextObject()); Assert.AreSame(get(tb, "a/c"), objw.nextObject()); Assert.AreSame(ta, objw.nextObject()); Assert.AreSame(get(ta, "a"), objw.nextObject()); Assert.AreSame(get(ta, "a/b"), objw.nextObject()); Assert.IsNull(objw.nextObject()); }
public virtual void ConcurrentRepack() { // // leave the syncPoint in broken state so any awaiting // threads and any threads that call await in the future get // the BrokenBarrierException // CyclicBarrier syncPoint = new CyclicBarrier(1); RevBlob a = tr.Blob("a"); tr.LightweightTag("t", a); ExecutorService pool = Executors.NewFixedThreadPool(2); try { _T187790690 repack1 = new _T187790690(this) { syncPoint = syncPoint }; //_T187790690 repack2 = new _T187790690(this) { syncPoint = syncPoint }; Future <int> result1 = pool.Submit(repack1); //Future<int> result2 = pool.Submit(repack2); NUnit.Framework.Assert.AreEqual(0, result1.Get()); // + result2.Get()); } finally { pool.Shutdown(); pool.AwaitTermination(long.MaxValue, TimeUnit.SECONDS); } }
public virtual void TestWhole_SmallObject() { int type = Constants.OBJ_BLOB; byte[] data = GetRng().NextBytes(300); RevBlob id = tr.Blob(data); tr.Branch("master").Commit().Add("A", id).Create(); tr.PackAndPrune(); NUnit.Framework.Assert.IsTrue(wc.Has(id), "has blob"); ObjectLoader ol = wc.Open(id); NUnit.Framework.Assert.IsNotNull(ol, "created loader"); NUnit.Framework.Assert.AreEqual(type, ol.GetType()); NUnit.Framework.Assert.AreEqual(data.Length, ol.GetSize()); NUnit.Framework.Assert.IsFalse(ol.IsLarge(), "is not large"); NUnit.Framework.Assert.IsTrue(Arrays.Equals(data, ol.GetCachedBytes()), "same content" ); ObjectStream @in = ol.OpenStream(); NUnit.Framework.Assert.IsNotNull(@in, "have stream"); NUnit.Framework.Assert.AreEqual(type, @in.GetType()); NUnit.Framework.Assert.AreEqual(data.Length, @in.GetSize()); byte[] data2 = new byte[data.Length]; IOUtil.ReadFully(@in, data2, 0, data.Length); NUnit.Framework.Assert.IsTrue(Arrays.Equals(data2, data), "same content"); NUnit.Framework.Assert.AreEqual(-1, @in.Read(), "stream at EOF"); @in.Close(); }
public virtual void TestPackWithTrailingGarbage() { TestRepository d = new TestRepository <FileRepository>(db); RevBlob a = d.Blob("a"); TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 1); pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4); a.CopyRawTo(pack); Deflate(pack, new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('b') }); Digest(pack); PackParser p = Index(new UnionInputStream(new ByteArrayInputStream(pack.ToByteArray ()), new ByteArrayInputStream(new byte[] { unchecked ((int)(0x7e)) }))); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(true); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("Pack with trailing garbage was accepted"); } catch (IOException err) { NUnit.Framework.Assert.AreEqual(MessageFormat.Format(JGitText.Get().expectedEOFReceived , "\\x7e"), err.Message); } }
public void testCull() { RevBlob f1 = blob("1"); RevBlob f2 = blob("2"); RevBlob f3 = blob("3"); RevBlob f4 = blob("4"); RevTree ta = tree(File("a/1", f1), File("c/3", f3)); RevCommit a = Commit(ta); RevTree tb = tree(File("a/1", f2), File("c/3", f3)); RevCommit b1 = Commit(tb, a); RevCommit b2 = Commit(tb, b1); RevTree tc = tree(File("a/1", f4)); RevCommit c1 = Commit(tc, a); RevCommit c2 = Commit(tc, c1); MarkStart(b2); MarkUninteresting(c2); AssertCommit(b2, objw.next()); AssertCommit(b1, objw.next()); Assert.IsNull(objw.next()); Assert.IsTrue(a.has(RevFlag.UNINTERESTING)); Assert.IsTrue(ta.has(RevFlag.UNINTERESTING)); Assert.IsTrue(f1.has(RevFlag.UNINTERESTING)); Assert.IsTrue(f3.has(RevFlag.UNINTERESTING)); Assert.AreSame(tb, objw.nextObject()); Assert.AreSame(get(tb, "a"), objw.nextObject()); Assert.AreSame(f2, objw.nextObject()); Assert.IsNull(objw.nextObject()); }
public void testTwoCommitTwoTreeTwoBlob() { RevBlob f0 = blob("0"); RevBlob f1 = blob("1"); RevBlob f2 = blob("0v2"); RevTree ta = tree(File("0", f0), File("1", f1), File("2", f1)); RevTree tb = tree(File("0", f2), File("1", f1), File("2", f1)); RevCommit a = Commit(ta); RevCommit b = Commit(tb, a); MarkStart(b); AssertCommit(b, objw.next()); AssertCommit(a, objw.next()); Assert.IsNull(objw.next()); Assert.AreSame(tb, objw.nextObject()); Assert.AreSame(f2, objw.nextObject()); Assert.AreSame(f1, objw.nextObject()); Assert.AreSame(ta, objw.nextObject()); Assert.AreSame(f0, objw.nextObject()); Assert.IsNull(objw.nextObject()); }
public virtual void TestWriteUnchangedFanout2_38() { RevBlob a = tr.Blob("a"); RevBlob b = tr.Blob("b"); RevBlob data1 = tr.Blob("data1"); RevBlob data2 = tr.Blob("data2"); RevCommit r = tr.Commit().Add(Fanout(2, a.Name), data1).Add(Fanout(2, b.Name), data2 ).Add(".gitignore", string.Empty).Add("zoo-animals.txt", string.Empty).Create(); // // // // // tr.ParseBody(r); NoteMap map = NoteMap.Read(reader, r); NUnit.Framework.Assert.IsTrue(map.Contains(a), "has note for a"); NUnit.Framework.Assert.IsTrue(map.Contains(b), "has note for b"); // This is a non-lazy map, so we'll be looking at the leaf buckets. RevCommit n = CommitNoteMap(map); NUnit.Framework.Assert.AreNotSame(r, n, "is new commit"); NUnit.Framework.Assert.AreSame(r.Tree, n.Tree, "same tree"); // Use a lazy-map for the next round of the same test. map = NoteMap.Read(reader, r); n = CommitNoteMap(map); NUnit.Framework.Assert.AreNotSame(r, n, "is new commit"); NUnit.Framework.Assert.AreSame(r.Tree, n.Tree, "same tree"); }
/** * Construct a regular file mode tree entry. * * @param path * path of the file. * @param blob * a blob, previously constructed in the repository. * @return the entry. * @throws Exception */ public DirCacheEntry file(String path, RevBlob blob) { DirCacheEntry e = new DirCacheEntry(path); e.setFileMode(FileMode.RegularFile); e.setObjectId(blob); return(e); }
/// <exception cref="System.Exception"></exception> public virtual TestRepository.CommitBuilder Add(string path, RevBlob id) { DirCacheEditor e = this.tree.Editor(); e.Add(new _PathEdit_790(id, path)); e.Finish(); return(this); }
public CommitBuilder add(String path, RevBlob id) { DirCacheEditor e = tree.editor(); e.add(new MockPathEdit(id, path)); e.finish(); return(this); }
protected static DirCacheEntry File(string path, RevBlob blob) { var e = new DirCacheEntry(path); e.setFileMode(FileMode.RegularFile); e.setObjectId(blob); return(e); }
public virtual void PackRefs_looseRefPacked() { RevBlob a = tr.Blob("a"); tr.LightweightTag("t", a); gc.PackRefs(); NUnit.Framework.Assert.AreEqual(repo.GetRef("t").GetStorage(), RefStorage.PACKED); }
public virtual void NonReferencedExpiredObject_pruned() { RevBlob a = tr.Blob("a"); gc.SetExpireAgeMillis(0); gc.Prune(Collections.EmptySet <ObjectId>()); NUnit.Framework.Assert.IsFalse(repo.HasObject(a)); }
public virtual void NonReferencedNonExpiredObject_notPruned() { RevBlob a = tr.Blob("a"); gc.SetExpire(Sharpen.Extensions.CreateDate(LastModified(a))); gc.Prune(Collections.EmptySet <ObjectId>()); NUnit.Framework.Assert.IsTrue(repo.HasObject(a)); }
public _Callable_185(GCTest _enclosing, RevBlob b, CyclicBarrier refUpdateLockedRef , CyclicBarrier packRefsDone) { this._enclosing = _enclosing; this.b = b; this.refUpdateLockedRef = refUpdateLockedRef; this.packRefsDone = packRefsDone; }
public virtual void LightweightTag_objectNotPruned() { RevBlob a = tr.Blob("a"); tr.LightweightTag("t", a); gc.SetExpireAgeMillis(0); gc.Prune(Collections.EmptySet <ObjectId>()); NUnit.Framework.Assert.IsTrue(repo.HasObject(a)); }
public override void SetUp() { base.SetUp(); tr = new TestRepository <Repository>(db); reader = db.NewObjectReader(); inserter = db.NewObjectInserter(); merger = new DefaultNoteMerger(); noteOn = tr.Blob("a"); baseNote = NewNote("data"); }
public virtual void TestUsingUnknownBlobFails() { // Try to use the 'n' blob that is not on the server. // TestRepository <Repository> s = new TestRepository <Repository>(src); RevBlob n = s.Blob("n"); RevCommit N = s.Commit().Parent(B).Add("q", n).Create(); // But don't include it in the pack. // TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 2); Copy(pack, src.Open(N)); Copy(pack, src.Open(s.ParseBody(N).Tree)); Digest(pack); TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024); PacketLineOut inPckLine = new PacketLineOut(inBuf); inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + N.Name + ' ' + "refs/heads/s" + '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS); inPckLine.End(); pack.WriteTo(inBuf, PM); TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024); ReceivePack rp = new ReceivePack(dst); rp.SetCheckReceivedObjects(true); rp.SetCheckReferencedObjectsAreReachable(true); rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook()); try { Receive(rp, inBuf, outBuf); NUnit.Framework.Assert.Fail("Expected UnpackException"); } catch (UnpackException failed) { Exception err = failed.InnerException; NUnit.Framework.Assert.IsTrue(err is MissingObjectException); MissingObjectException moe = (MissingObjectException)err; NUnit.Framework.Assert.AreEqual(n, moe.GetObjectId()); } PacketLineIn r = AsPacketLineIn(outBuf); string master = r.ReadString(); int nul = master.IndexOf('\0'); NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list"); NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring (master, 0, nul)); NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString()); NUnit.Framework.Assert.AreEqual("unpack error Missing blob " + n.Name, r.ReadString ()); NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString ()); NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString()); }
public virtual void NonReferencedObjects_onlyExpiredPruned() { RevBlob a = tr.Blob("a"); gc.SetExpire(Sharpen.Extensions.CreateDate(LastModified(a) + 1)); FsTick(); RevBlob b = tr.Blob("b"); gc.Prune(Collections.EmptySet <ObjectId>()); NUnit.Framework.Assert.IsFalse(repo.HasObject(a)); NUnit.Framework.Assert.IsTrue(repo.HasObject(b)); }
public virtual void AnnotatedTag_objectNotPruned() { RevBlob a = tr.Blob("a"); RevTag t = tr.Tag("t", a); // this doesn't create the refs/tags/t ref tr.LightweightTag("t", t); gc.SetExpireAgeMillis(0); gc.Prune(Collections.EmptySet <ObjectId>()); NUnit.Framework.Assert.IsTrue(repo.HasObject(t)); NUnit.Framework.Assert.IsTrue(repo.HasObject(a)); }
public virtual void TestEditDeleteConflict() { NoteMapMerger merger = new NoteMapMerger(db, new DefaultNoteMerger(), null); NoteMap result; NoteMap map_a_b1 = NoteMap.Read(reader, sampleTree_a_b); string noteBContent1 = noteBContent + "change"; RevBlob noteBBlob1 = tr.Blob(noteBContent1); map_a_b1.Set(noteBId, noteBBlob1); map_a_b1.WriteTree(inserter); result = merger.Merge(map_a_b, map_a_b1, map_a); NUnit.Framework.Assert.AreEqual(2, CountNotes(result)); NUnit.Framework.Assert.AreEqual(noteABlob, result.Get(noteAId)); NUnit.Framework.Assert.AreEqual(noteBBlob1, result.Get(noteBId)); }
public virtual void TestAddDifferentNotes() { NoteMapMerger merger = new NoteMapMerger(db, null, null); NoteMap result; NoteMap map_a_c = NoteMap.Read(reader, sampleTree_a); RevBlob noteCId = tr.Blob("c"); RevBlob noteCBlob = tr.Blob("noteCContent"); map_a_c.Set(noteCId, noteCBlob); map_a_c.WriteTree(inserter); result = merger.Merge(map_a, map_a_b, map_a_c); NUnit.Framework.Assert.AreEqual(3, CountNotes(result)); NUnit.Framework.Assert.AreEqual(noteABlob, result.Get(noteAId)); NUnit.Framework.Assert.AreEqual(noteBBlob, result.Get(noteBId)); NUnit.Framework.Assert.AreEqual(noteCBlob, result.Get(noteCId)); }
public virtual void TestGetCachedBytes() { string exp = "this is test data"; RevBlob a = tr.Blob("a"); RevBlob data = tr.Blob(exp); RevCommit r = tr.Commit().Add(a.Name, data).Create(); // // tr.ParseBody(r); NoteMap map = NoteMap.Read(reader, r); byte[] act = map.GetCachedBytes(a, exp.Length * 4); NUnit.Framework.Assert.IsNotNull(act, "has data for a"); NUnit.Framework.Assert.AreEqual(exp, RawParseUtils.Decode(act)); }
public virtual void TestEditFlat() { RevBlob a = tr.Blob("a"); RevBlob b = tr.Blob("b"); RevBlob data1 = tr.Blob("data1"); RevBlob data2 = tr.Blob("data2"); RevCommit r = tr.Commit().Add(a.Name, data1).Add(b.Name, data2).Add(".gitignore", string.Empty).Add("zoo-animals.txt", b).Create(); // // // // // tr.ParseBody(r); NoteMap map = NoteMap.Read(reader, r); map.Set(a, data2); map.Set(b, null); map.Set(data1, b); map.Set(data2, null); NUnit.Framework.Assert.AreEqual(data2, map.Get(a)); NUnit.Framework.Assert.AreEqual(b, map.Get(data1)); NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b"); NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2"); MutableObjectId id = new MutableObjectId(); for (int p = 42; p > 0; p--) { id.SetByte(1, p); map.Set(id, data1); } for (int p_1 = 42; p_1 > 0; p_1--) { id.SetByte(1, p_1); NUnit.Framework.Assert.IsTrue(map.Contains(id), "contains " + id); } RevCommit n = CommitNoteMap(map); map = NoteMap.Read(reader, n); NUnit.Framework.Assert.AreEqual(data2, map.Get(a)); NUnit.Framework.Assert.AreEqual(b, map.Get(data1)); NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b"); NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2"); NUnit.Framework.Assert.AreEqual(b, TreeWalk.ForPath(reader, "zoo-animals.txt", n. Tree).GetObjectId(0)); }
public virtual void TestRemoveDeletesTreeFanout2_38() { RevBlob a = tr.Blob("a"); RevBlob data1 = tr.Blob("data1"); RevTree empty = tr.Tree(); RevCommit r = tr.Commit().Add(Fanout(2, a.Name), data1).Create(); // // tr.ParseBody(r); NoteMap map = NoteMap.Read(reader, r); map.Set(a, null); RevCommit n = CommitNoteMap(map); NUnit.Framework.Assert.AreEqual(empty, n.Tree, "empty tree"); }