Example #1
0
 /// <exception cref="System.IO.IOException"></exception>
 private ObjectId BuildTree(Dictionary<string, string> headEntries)
 {
     DirCache lockDirCache = DirCache.NewInCore();
     // assertTrue(lockDirCache.lock());
     DirCacheEditor editor = lockDirCache.Editor();
     if (headEntries != null)
     {
         foreach (KeyValuePair<string, string> e in headEntries.EntrySet())
         {
             DirCacheCheckoutTest.AddEdit addEdit = new DirCacheCheckoutTest.AddEdit(e.Key, GenSha1
                 (e.Value), e.Value.Length);
             editor.Add(addEdit);
         }
     }
     editor.Finish();
     return lockDirCache.WriteTree(db.NewObjectInserter());
 }
Example #2
0
 /// <exception cref="System.IO.IOException"></exception>
 private void BuildIndex(Dictionary<string, string> indexEntries)
 {
     dirCache = new DirCache(db.GetIndexFile(), db.FileSystem);
     if (indexEntries != null)
     {
         NUnit.Framework.Assert.IsTrue(dirCache.Lock());
         DirCacheEditor editor = dirCache.Editor();
         foreach (KeyValuePair<string, string> e in indexEntries.EntrySet())
         {
             WriteTrashFile(e.Key, e.Value);
             ObjectInserter inserter = db.NewObjectInserter();
             ObjectId id = inserter.Insert(Constants.OBJ_BLOB, Constants.Encode(e.Value));
             editor.Add(new DirCacheEditor.DeletePath(e.Key));
             editor.Add(new _PathEdit_284(id, e.Key));
         }
         NUnit.Framework.Assert.IsTrue(editor.Commit());
     }
 }
Example #3
0
		/// <exception cref="System.IO.IOException"></exception>
		private void BuildIndex(Dictionary<string, string> indexEntries)
		{
			GitIndex index = new GitIndex(db);
			if (indexEntries != null)
			{
				foreach (KeyValuePair<string, string> e in indexEntries.EntrySet())
				{
					index.Add(trash, WriteTrashFile(e.Key, e.Value)).ForceRecheck();
				}
			}
			index.Write();
			db.GetIndex().Read();
		}
Example #4
0
		/// <exception cref="System.IO.IOException"></exception>
		private Tree BuildTree(Dictionary<string, string> headEntries)
		{
			Tree tree = new Tree(db);
			if (headEntries == null)
			{
				return tree;
			}
			FileTreeEntry fileEntry;
			Tree parent;
			ObjectInserter oi = db.NewObjectInserter();
			try
			{
				foreach (KeyValuePair<string, string> e in headEntries.EntrySet())
				{
					fileEntry = tree.AddFile(e.Key);
					fileEntry.SetId(GenSha1(e.Value));
					parent = fileEntry.GetParent();
					while (parent != null)
					{
						parent.SetId(oi.Insert(Constants.OBJ_TREE, parent.Format()));
						parent = parent.GetParent();
					}
				}
				oi.Flush();
			}
			finally
			{
				oi.Release();
			}
			return tree;
		}
        // [Test] // LUCENENET NOTE: For now, we are overriding this test in every subclass to pull it into the right context for the subclass
        public virtual void TestRandomSortedBytes()
        {
            Directory dir = NewDirectory();
            IndexWriterConfig cfg = NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random()));
            if (!DefaultCodecSupportsDocsWithField())
            {
                // if the codec doesnt support missing, we expect missing to be mapped to byte[]
                // by the impersonator, but we have to give it a chance to merge them to this
                cfg.SetMergePolicy(NewLogMergePolicy());
            }
            RandomIndexWriter w = new RandomIndexWriter(Random(), dir, cfg);
            int numDocs = AtLeast(100);
            BytesRefHash hash = new BytesRefHash();
            IDictionary<string, string> docToString = new Dictionary<string, string>();
            int maxLength = TestUtil.NextInt(Random(), 1, 50);
            for (int i = 0; i < numDocs; i++)
            {
                Document doc = new Document();
                doc.Add(NewTextField("id", "" + i, Field.Store.YES));
                string @string = TestUtil.RandomRealisticUnicodeString(Random(), 1, maxLength);
                BytesRef br = new BytesRef(@string);
                doc.Add(new SortedDocValuesField("field", br));
                hash.Add(br);
                docToString["" + i] = @string;
                w.AddDocument(doc);
            }
            if (Rarely())
            {
                w.Commit();
            }
            int numDocsNoValue = AtLeast(10);
            for (int i = 0; i < numDocsNoValue; i++)
            {
                Document doc = new Document();
                doc.Add(NewTextField("id", "noValue", Field.Store.YES));
                w.AddDocument(doc);
            }
            if (!DefaultCodecSupportsDocsWithField())
            {
                BytesRef bytesRef = new BytesRef();
                hash.Add(bytesRef); // add empty value for the gaps
            }
            if (Rarely())
            {
                w.Commit();
            }
            if (!DefaultCodecSupportsDocsWithField())
            {
                // if the codec doesnt support missing, we expect missing to be mapped to byte[]
                // by the impersonator, but we have to give it a chance to merge them to this
                w.ForceMerge(1);
            }
            for (int i = 0; i < numDocs; i++)
            {
                Document doc = new Document();
                string id = "" + i + numDocs;
                doc.Add(NewTextField("id", id, Field.Store.YES));
                string @string = TestUtil.RandomRealisticUnicodeString(Random(), 1, maxLength);
                BytesRef br = new BytesRef(@string);
                hash.Add(br);
                docToString[id] = @string;
                doc.Add(new SortedDocValuesField("field", br));
                w.AddDocument(doc);
            }
            w.Commit();
            IndexReader reader = w.Reader;
            SortedDocValues docValues = MultiDocValues.GetSortedValues(reader, "field");
            int[] sort = hash.Sort(BytesRef.UTF8SortedAsUnicodeComparer);
            BytesRef expected = new BytesRef();
            BytesRef actual = new BytesRef();
            Assert.AreEqual(hash.Size(), docValues.ValueCount);
            for (int i = 0; i < hash.Size(); i++)
            {
                hash.Get(sort[i], expected);
                docValues.LookupOrd(i, actual);
                Assert.AreEqual(expected.Utf8ToString(), actual.Utf8ToString());
                int ord = docValues.LookupTerm(expected);
                Assert.AreEqual(i, ord);
            }
            AtomicReader slowR = SlowCompositeReaderWrapper.Wrap(reader);
            ISet<KeyValuePair<string, string>> entrySet = docToString.EntrySet();

            foreach (KeyValuePair<string, string> entry in entrySet)
            {
                // pk lookup
                DocsEnum termDocsEnum = slowR.TermDocsEnum(new Term("id", entry.Key));
                int docId = termDocsEnum.NextDoc();
                expected = new BytesRef(entry.Value);
                docValues.Get(docId, actual);
                Assert.AreEqual(expected, actual);
            }

            reader.Dispose();
            w.Dispose();
            dir.Dispose();
        }
			/// <exception cref="System.IO.IOException"></exception>
			internal override void ConfigureRequest(HttpURLConnection conn)
			{
				IDictionary<string, string> p = new Dictionary<string, string>(@params);
				p.Put("username", user);
				string realm = p.Get("realm");
				string nonce = p.Get("nonce");
				string uri = p.Get("uri");
				string qop = p.Get("qop");
				string method = conn.GetRequestMethod();
				string A1 = user + ":" + realm + ":" + pass;
				string A2 = method + ":" + uri;
				string expect;
				if ("auth".Equals(qop))
				{
					string c = p.Get("cnonce");
					string nc = string.Format("%08x", ++requestCount);
					p.Put("nc", nc);
					expect = KD(H(A1), nonce + ":" + nc + ":" + c + ":" + qop + ":" + H(A2));
				}
				else
				{
					expect = KD(H(A1), nonce + ":" + H(A2));
				}
				p.Put("response", expect);
				StringBuilder v = new StringBuilder();
				foreach (KeyValuePair<string, string> e in p.EntrySet())
				{
					if (v.Length > 0)
					{
						v.Append(", ");
					}
					v.Append(e.Key);
					v.Append('=');
					v.Append('"');
					v.Append(e.Value);
					v.Append('"');
				}
				conn.SetRequestProperty(HttpSupport.HDR_AUTHORIZATION, NAME + " " + v);
			}