Exemplo n.º 1
0
        private void CreateTestSite()
        {
            // need to reset the pinned site list
            var action = new PortalContext.ReloadSiteListDistributedAction();

            action.ExecuteAsync(CancellationToken.None).GetAwaiter().GetResult();

            var sites = new GenericContent(Repository.Root, "Sites")
            {
                Name = "Sites"
            };

            sites.Save();

            var site = new Site(sites)
            {
                Name    = "Fake Test Site",
                UrlList = new Dictionary <string, string> {
                    { "localhost_forms", "Forms" },
                    { "localhost_windows", "Windows" },
                    { "localhost_none", "None" }
                }
            };

            site.Save();
        }
Exemplo n.º 2
0
        private static void DoBenchmarkSteps()
        {
            var root = Node.Load <Folder>("/Root/Timing_TestRoot/STU");
            int id   = 0;

            Node n = null;

            for (int i = 0; i < 5; i++)
            {
                n = new GenericContent(root, "Car");
                n.Save();
            }
            id = n.Id;

            Node node;

            for (var i = 0; i < 5; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    node = Node.LoadNode(id);
                    var sb = new StringBuilder();
                    foreach (var proptype in node.PropertyTypes)
                    {
                        sb.Append(node.GetProperty <object>(proptype));
                    }
                }
                node = Node.LoadNode(id);
                node.Index++;
                node.Save();
            }
        }
Exemplo n.º 3
0
        private Tuple <List <GenericContent>, int, int> InitCarsForUnprocessedTests()
        {
            // init: create some cars
            var container = new Folder(TestRoot);

            container.Name = "unprocessedtest-" + Guid.NewGuid().ToString();
            container.Save();

            var lastActivityId = IndexingActivityManager.GetLastActivityId();

            var carlist = new List <GenericContent>();

            for (var i = 0; i < 10; i++)
            {
                var car = new GenericContent(container, "Car");
                car.Name = "testcar" + i.ToString();
                car.Save();
                carlist.Add(car);
            }

            var expectedLastActivityId = IndexingActivityManager.GetLastActivityId();

            // check1: cars can be found in the index
            for (var i = 0; i < carlist.Count; i++)
            {
                Assert.IsTrue(CheckCarInIndex(carlist[i].Id), "Car cannot be found in index after init.");
            }

            return(new Tuple <List <GenericContent>, int, int>(carlist, lastActivityId, expectedLastActivityId));
        }
Exemplo n.º 4
0
        public void ContentList_Concurrent_AddStringField()
        {
            string listDef0 = @"<?xml version='1.0' encoding='utf-8'?>
                <ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	                <Fields>
		                <ContentListField name='#StringField1' type='ShortText' />
	                </Fields>
                </ContentListDefinition>
                ";

            string path = RepositoryPath.Combine(this.TestRoot.Path, "Cars");

            if (Node.Exists(path))
            {
                Node.ForceDelete(path);
            }

            var list = new ContentList(this.TestRoot);

            list.Name = "Cars";
            list.ContentListDefinition = listDef0;
            list.AllowedChildTypes     = new ContentType[] { ContentType.GetByName("Car") };

            list.Save();
            var listId = list.Id;

            Node car = new GenericContent(list, "Car");

            car.Name         = "Trabant Tramp";
            car["#String_0"] = "ABC 34-78";
            car.Save();

            var t1 = new System.Threading.Thread(ContentList_Concurrent_AddStringField_Thread);
            var t2 = new System.Threading.Thread(ContentList_Concurrent_AddStringField_Thread);

            t1.Start();
            t2.Start();

            var startingTime = DateTime.UtcNow;

            while (counter < 2)
            {
                System.Threading.Thread.Sleep(1000);
                if ((DateTime.UtcNow - startingTime).TotalSeconds > 10)
                {
                    break;
                }
            }
            if (t1.ThreadState == System.Threading.ThreadState.Running)
            {
                t1.Abort();
            }
            if (t2.IsAlive)
            {
                t2.Abort();
            }

            Assert.IsTrue(counter == 2);
        }
Exemplo n.º 5
0
        public void ContentList_1()
        {
            string listDef = @"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<DisplayName>Cars title</DisplayName>
	<Description>Cars description</Description>
	<Icon>automobile.gif</Icon>
	<Fields>
		<ContentListField name='#ListField1' type='ShortText'>
			<DisplayName>ContentListField1</DisplayName>
			<Description>ContentListField1 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
				<MaxLength>100</MaxLength>
			</Configuration>
		</ContentListField>
		<ContentListField name='#ListField2' type='WhoAndWhen'>
			<DisplayName>ContentListField2</DisplayName>
			<Description>ContentListField2 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
			</Configuration>
		</ContentListField>
		<ContentListField name='#ListField3' type='ShortText'>
			<DisplayName>ContentListField3</DisplayName>
			<Description>ContentListField3 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
				<MaxLength>200</MaxLength>
			</Configuration>
		</ContentListField>
	</Fields>
</ContentListDefinition>
";
            string path    = RepositoryPath.Combine(this.TestRoot.Path, "Cars");

            if (Node.Exists(path))
            {
                Node.ForceDelete(path);
            }

            ContentList list = new ContentList(this.TestRoot);

            list.Name = "Cars";
            list.ContentListDefinition = listDef;
            list.AllowedChildTypes     = new ContentType[] { ContentType.GetByName("Car") };

            list.Save();

            Node car = new GenericContent(list, "Car");

            car.Name         = "Kispolszki";
            car["#String_0"] = "ABC 34-78";
            car.Save();

            Content content = Content.Create(car);

            //-- Sikeres, ha nem dob hibat
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates a new Like for the given Post/Content/Comment
        /// </summary>
        /// <param name="clientId"></param>
        /// <param name="contextPath">New posts from journal items will be created under contextPath</param>
        /// <returns></returns>
        public static void CreateLike(string clientId, string contextPath, out int postId)
        {
            var likedContent = GetPostFromId(clientId, contextPath);

            var likesFolder = Node.LoadNode(RepositoryPath.Combine(likedContent.Path, "Likes")) as GenericContent;

            if (likesFolder == null)
            {
                likesFolder        = new SystemFolder(likedContent) as GenericContent;
                likesFolder.Name   = "Likes";
                likesFolder.Hidden = true;
                likesFolder.Save();
            }

            var likeContent = new GenericContent(likesFolder, "Like");

            likeContent.Save();

            // return postId, as it will be used for LikeList and LikeMarkup
            postId = likedContent.Id;
        }
Exemplo n.º 7
0
        private void CreateTestSite()
        {
            var sites = new GenericContent(Repository.Root, "Sites")
            {
                Name = "Sites"
            };

            sites.Save();

            var site = new Site(sites)
            {
                Name    = "Fake Test Site",
                UrlList = new Dictionary <string, string> {
                    { "localhost_forms", "Forms" },
                    { "localhost_windows", "Windows" },
                    { "localhost_none", "None" }
                }
            };

            site.Save();
        }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new Comment for the given Post/Content
        /// </summary>
        /// <param name="clientId"></param>
        /// <param name="contextPath">New posts from journal items will be created under contextPath</param>
        /// <param name="text"></param>
        /// <returns></returns>
        public static GenericContent CreateComment(string clientId, string contextPath, string text)
        {
            var post = GetPostFromId(clientId, contextPath);

            var commentsFolder = Node.LoadNode(RepositoryPath.Combine(post.Path, "Comments")) as GenericContent;

            if (commentsFolder == null)
            {
                commentsFolder        = new SystemFolder(post) as GenericContent;
                commentsFolder.Name   = "Comments";
                commentsFolder.Hidden = true;
                commentsFolder.Save();
            }

            var comment = new GenericContent(commentsFolder, "Comment");

            //var comment = new GenericContent(post, "Comment");
            comment.Description = text;
            comment.Save();
            return(comment);
        }
Exemplo n.º 9
0
        /// <summary>
        /// Creates a new Post under the given contextpath
        /// </summary>
        /// <param name="actualContextPath">New posts from journal items will be created under contextPath</param>
        /// <param name="text"></param>
        /// <param name="creationDate"></param>
        /// <param name="journalId">The post may be automatically created from a journal item, in this case the journal id is passed</param>
        /// <returns></returns>
        public static GenericContent CreatePost(string contextPath, string text, int journalId, PostType type, Node sharedContent, string details)
        {
            var actualContextPath = contextPath;

            if (type != PostType.BigPost)
            {
                // for journals the context should always be its parent wall workspace. That's where the post will be saved.
                var ws = Workspace.GetWorkspaceWithWallForNode(sharedContent);
                if (ws != null)
                {
                    actualContextPath = ws.Path;
                }
            }
            var postsPath   = RepositoryPath.Combine(actualContextPath, "Posts");
            var postsFolder = Node.LoadNode(postsPath) as GenericContent;

            if (postsFolder == null)
            {
                using (new SystemAccount())
                {
                    var context = Node.LoadNode(actualContextPath);
                    postsFolder        = new GenericContent(context, "Posts");
                    postsFolder.Name   = "Posts";
                    postsFolder.Hidden = true;
                    postsFolder.Save();
                }
            }
            var post = new GenericContent(postsFolder, "Post");

            post.Description    = text;
            post["JournalId"]   = journalId;
            post["PostType"]    = type;
            post["PostDetails"] = details;
            if (sharedContent != null)
            {
                post.SetReference("SharedContent", sharedContent);
            }
            post.Save();
            return(post);
        }
Exemplo n.º 10
0
        public void ContentList_WithoutDefinition()
        {
            string path = RepositoryPath.Combine(this.TestRoot.Path, "Cars");

            if (Node.Exists(path))
            {
                Node.ForceDelete(path);
            }

            ContentList list = new ContentList(this.TestRoot);

            list.Name = "Cars";
            list.AllowedChildTypes = new ContentType[] { ContentType.GetByName("Car") };

            list.Save();

            Node car = new GenericContent(list, "Car");

            car.Name = "Kispolszki";
            car.Save();

            //-- Sikeres, ha nem dob hibat
        }
Exemplo n.º 11
0
        public void IndexingHistory_FixAddUpdateOverlap()
        {
            // add overlaps with update
            var fieldvalue1 = "IndexingHistoryFixAddUpdateOverlapFirst";
            var fieldvalue2 = "IndexingHistoryFixAddUpdateOverlapSecond";

            var history = LuceneManager._history;

            var car = new GenericContent(TestRoot, "Car");

            car.Name = Guid.NewGuid().ToString();
            car.Save();
            var id = car.Id;


            // init 1
            var node1 = Node.LoadNode(id);

            node1["Description"] = fieldvalue1;
            node1.Save();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node1.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node1.VersionId);

            var docInfo1  = IndexDocumentInfo.Create(node1, false);
            var docData1  = DataBackingStore.CreateIndexDocumentData(node1, docInfo1, null, null);
            var document1 = IndexDocumentInfo.CreateDocument(docInfo1, docData1);


            // init 2
            var node2 = Node.LoadNode(id);

            node2["Description"] = fieldvalue2;
            node2.Save();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node2.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node2.VersionId);

            var docInfo2  = IndexDocumentInfo.Create(node2, false);
            var docData2  = DataBackingStore.CreateIndexDocumentData(node2, docInfo2, null, null);
            var document2 = IndexDocumentInfo.CreateDocument(docInfo2, docData2);


            // 1 check indexing history
            var versionId1 = history.GetVersionId(document1);
            var timestamp1 = history.GetTimestamp(document1);
            var historyOk  = LuceneManager._history.CheckForAdd(versionId1, timestamp1);

            // timestamp in indexing history should be the newest
            var actTimestamp1 = history.Get(versionId1);

            Assert.AreEqual(timestamp1, actTimestamp1, "Timestamp in indexing history did not change.");
            Assert.IsTrue(historyOk, "History indicates indexing should not be executed, but this is not true.");


            // 2 check indexing history
            var versionId2 = history.GetVersionId(document2);
            var timestamp2 = history.GetTimestamp(document2);

            historyOk = LuceneManager._history.CheckForUpdate(versionId2, timestamp2);


            // timestamp in indexing history should change
            var actTimestamp2 = history.Get(versionId2);

            Assert.AreEqual(timestamp2, actTimestamp2, "Timestamp in indexing history did not change.");
            Assert.IsTrue(historyOk, "History indicates indexing should not be executed, but this is not true.");


            // 2 index
            var document   = document2;
            var updateTerm = UpdateDocumentActivity.GetIdTerm(document);

            LuceneManager.SetFlagsForUpdate(document);
            LuceneManager._writer.UpdateDocument(updateTerm, document);


            var firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings {
                EnableAutofilters = FilterStatus.Disabled
            }).Count;
            var secondfound = ContentQuery.Query("Description:" + fieldvalue2, new QuerySettings {
                EnableAutofilters = FilterStatus.Disabled
            }).Count;

            // check indexing occured correctly
            // thread 2 writes values in index
            Assert.AreEqual(0, firstfound);
            Assert.AreEqual(1, secondfound);


            // 1 index
            document = document1;
            LuceneManager._writer.AddDocument(document);


            firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings {
                EnableAutofilters = FilterStatus.Disabled
            }).Count;
            secondfound = ContentQuery.Query("Description:" + fieldvalue2, new QuerySettings {
                EnableAutofilters = FilterStatus.Disabled
            }).Count;

            // check indexing occured correctly
            // thread 1 adds values to index, duplication occurs
            Assert.AreEqual(1, firstfound);
            Assert.AreEqual(1, secondfound);


            // 1 detects problem
            var detectChange1 = history.CheckHistoryChange(versionId1, timestamp1);

            Assert.IsTrue(detectChange1, "Thread 1 did not detect indexing overlapping although it should have.");

            // 2 detects no problem
            var detectChange2 = history.CheckHistoryChange(versionId2, timestamp2);

            Assert.IsFalse(detectChange2, "Thread 2 detected indexing overlapping although it should not have.");


            // 1 fixes index
            LuceneManager.RefreshDocument(versionId1, false);

            firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings {
                EnableAutofilters = FilterStatus.Disabled
            }).Count;
            //secondfound = ContentQuery.Query("Description:" + fieldvalue2, new QuerySettings { EnableAutofilters = FilterStatus.Disabled }).Count;
            var q = LucQuery.Parse("Description:" + fieldvalue2);

            q.EnableAutofilters = FilterStatus.Disabled;
            secondfound         = q.Execute(true).Count();

            Assert.AreEqual(0, firstfound);
            Assert.AreEqual(1, secondfound);

            var node = Node.LoadNode(id);

            node.ForceDelete();
        }
Exemplo n.º 12
0
        private Tuple<List<GenericContent>, int, int> InitCarsForUnprocessedTests()
        {
            // init: create some cars
            var container = new Folder(TestRoot);
            container.Name = "unprocessedtest-" + Guid.NewGuid().ToString();
            container.Save();

            var lastActivityId = IndexingActivityManager.GetLastActivityId();

            var carlist = new List<GenericContent>();
            for (var i = 0; i < 10; i++)
            {
                var car = new GenericContent(container, "Car");
                car.Name = "testcar" + i.ToString();
                car.Save();
                carlist.Add(car);
            }

            var expectedLastActivityId = IndexingActivityManager.GetLastActivityId();

            // check1: cars can be found in the index
            for (var i = 0; i < carlist.Count; i++)
            {
                Assert.IsTrue(CheckCarInIndex(carlist[i].Id), "Car cannot be found in index after init.");
            }

            return new Tuple<List<GenericContent>, int, int>(carlist, lastActivityId, expectedLastActivityId);
        }
Exemplo n.º 13
0
        public void ContentList_Modify()
		{
			List<string> listDefs = new List<string>();
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<Fields>
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF1' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<Fields>
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF1' type='ShortText' />
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF1' type='ShortText' />
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF3' type='ShortText' />
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF1' type='ShortText' />
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");

			string listName = "List1";
            string listPath = RepositoryPath.Combine(this.TestRoot.Path, listName);
            if (Node.Exists(listPath))
                Node.ForceDelete(listPath);

			ContentList list = new ContentList(this.TestRoot);
            list.Name = listName;
            list.AllowedChildTypes = new ContentType[] { ContentType.GetByName("Car") };

            list.Save();

            Node car = new GenericContent(list, "Car");
			car.Name = "Kispolszki";
			car.Save();
			int carId = car.Id;

			StringBuilder log = new StringBuilder();
            for (int def = 0; def < listDefs.Count; def++)
			{
                Exception ex = null;
                for (var i = 0; i < 10; i++)
                {
                    try
                    {
                        ex = null;
                        list = Node.Load<ContentList>(listPath);
                        list.ContentListDefinition = listDefs[def];
                        list.Save();
                        break;
                    }
                    catch(Exception e)
                    {
                        ex = e;
                        System.Threading.Thread.Sleep(200);
Debug.WriteLine("@> {0}. {1} / {2}", i, def, listDefs.Count);
                    }
                }
                if (ex != null)
                    throw new ApplicationException("Exception after 10 iteration: " + ex.Message, ex);


				car = Node.LoadNode(carId);
				log.Append("Def_").Append(def).Append(": ");
				for (int i = 0; i < 4; i++)
				{
					var propName = "#String_" + i;
					if(car.HasProperty(propName))
						log.Append("[").Append(propName).Append(" = ").Append(car.PropertyTypes[propName].Mapping).Append("]");
				}
				log.Append("\r\n");
			}

			string realLog = log.Replace("\r\n", "").Replace(" ", "").Replace("\t", "").ToString();
			string expectedLog = @"
				Def_0: 
				Def_1: [#String_0 = 800000000][#String_1 = 800000001]
				Def_2: [#String_0 = 800000000]
				Def_3: 
				Def_4: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002]
				Def_5: [#String_0 = 800000000][#String_2 = 800000002]
				Def_6: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002]
				Def_7: [#String_2 = 800000002]
				Def_8: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002]
				Def_9: [#String_0 = 800000000][#String_2 = 800000002][#String_3 = 800000003]
				".Replace("\r\n", "").Replace(" ", "").Replace("\t", "");

			Assert.IsTrue(realLog == expectedLog);
		}
Exemplo n.º 14
0
        public void IndexingHistory_FixDeleteUpdateOverlap()
        {
            // delete overlaps with update
            var fieldvalue1 = "IndexingHistoryFixDeleteAddOverlap";

            var history = LuceneManager._history;

            var car = new GenericContent(TestRoot, "Car");
            car.Name = Guid.NewGuid().ToString();
            car.Save();
            var id = car.Id;


            // init 2
            var node2 = Node.LoadNode(id);
            node2["Description"] = fieldvalue1;
            node2.Save();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node2.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node2.VersionId);

            var docInfo2 = IndexDocumentInfo.Create(node2);
            var docData2 = DataBackingStore.CreateIndexDocumentData(node2, docInfo2, null);
            var document2 = IndexDocumentInfo.CreateDocument(docInfo2, docData2);


            // init 1
            var node1 = Node.LoadNode(id);
            node1.ForceDelete();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node1.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node1.VersionId);



            // 1 check indexing history
            var versionId1 = node2.VersionId;
            var term = new Term(LucObject.FieldName.VersionId, Lucene.Net.Util.NumericUtils.IntToPrefixCoded(versionId1));
            LuceneManager._history.ProcessDelete(new Term[] { term });


            // timestamp in indexing history should change
            var actTimestamp1 = history.Get(versionId1);
            Assert.AreEqual(long.MaxValue, actTimestamp1, "Timestamp in indexing history did not change.");


            // 2 check indexing history
            var versionId2 = history.GetVersionId(document2);
            var timestamp2 = history.GetTimestamp(document2);
            var historyOk = LuceneManager._history.CheckForUpdate(versionId2, timestamp2);


            // timestamp in indexing history should not change
            var actTimestamp2 = history.Get(versionId2);
            Assert.AreNotEqual(timestamp2, actTimestamp2, "Timestamp in indexing history changed, although it should not have.");
            Assert.IsFalse(historyOk, "History indicates indexing can be executed, but this is not true.");

            // 2 does not continue, returns

            // 1 deletes index
            LuceneManager.SetFlagsForDelete(term);
            LuceneManager._writer.DeleteDocuments(term);


            var firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count;

            // check indexing occured correctly
            // thread 1 deletes from index
            Assert.AreEqual(0, firstfound);
        }
Exemplo n.º 15
0
        public static void CreateSandbox(TestContext testContext)
        {
            var site = Node.Load <Site>("/Root/TestSiteForAppModelTest");

            if (site == null)
            {
                site      = new Site(Repository.Root);
                site.Name = "TestSiteForAppModelTest";
                var urlList = new Dictionary <string, string>();
                urlList.Add("testhost", "Windows");
                site.UrlList = urlList;
                site.Save();
            }
            var homePage   = EnsureSiteStartPage(site);
            var webContent = Node.Load <GenericContent>("/Root/TestSiteForAppModelTest/Home/WebContent1");

            if (webContent == null)
            {
                webContent      = new GenericContent(homePage, "WebContent");
                webContent.Name = "WebContent1";
                webContent.Save();
            }
            var file = Node.Load <File>("/Root/TestSiteForAppModelTest/Home/File1");

            if (file == null)
            {
                file      = new File(homePage);
                file.Name = "File1";
                file.GetBinary("Binary").SetStream(Tools.GetStreamFromString("File1 content"));
                file.Binary.FileName = "1.txt";
                file.Save();
            }

            //---- Appmodel

            var siteAppsFolder = Node.Load <SystemFolder>("/Root/TestSiteForAppModelTest/(apps)");

            if (siteAppsFolder == null)
            {
                siteAppsFolder      = new SystemFolder(site);
                siteAppsFolder.Name = "(apps)";
                siteAppsFolder.Save();
            }
            var siteAppsPageFolder = Node.Load <Folder>("/Root/TestSiteForAppModelTest/(apps)/Page");

            if (siteAppsPageFolder == null)
            {
                siteAppsPageFolder      = new SystemFolder(siteAppsFolder);
                siteAppsPageFolder.Name = "Page";
                siteAppsPageFolder.Save();
            }
            var siteAppsPageBrowsePage = Node.Load <Page>("/Root/TestSiteForAppModelTest/(apps)/Page/Browse");

            if (siteAppsPageBrowsePage == null)
            {
                siteAppsPageBrowsePage      = new Page(siteAppsPageFolder);
                siteAppsPageBrowsePage.Name = "Browse";
                siteAppsPageBrowsePage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>Page Browse App</h1></body></html>"));
                siteAppsPageBrowsePage.Binary.FileName = "1.html";
                siteAppsPageBrowsePage.Save();
            }
            var siteAppsPageEditPage = Node.Load <Page>("/Root/TestSiteForAppModelTest/(apps)/Page/Edit");

            if (siteAppsPageEditPage == null)
            {
                siteAppsPageEditPage      = new Page(siteAppsPageFolder);
                siteAppsPageEditPage.Name = "Edit";
                siteAppsPageEditPage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>Page EditPage</h1></body></html>"));
                siteAppsPageEditPage.Binary.FileName = "1.html";
                siteAppsPageEditPage.Save();
            }

            var siteAppsGenericContentFolder = Node.Load <Folder>("/Root/TestSiteForAppModelTest/(apps)/GenericContent");

            if (siteAppsGenericContentFolder == null)
            {
                siteAppsGenericContentFolder      = new SystemFolder(siteAppsFolder);
                siteAppsGenericContentFolder.Name = "GenericContent";
                siteAppsGenericContentFolder.Save();
            }
            var siteAppsGenericContentBrowsePage = Node.Load <Page>("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Browse");

            if (siteAppsGenericContentBrowsePage == null)
            {
                siteAppsGenericContentBrowsePage      = new Page(siteAppsGenericContentFolder);
                siteAppsGenericContentBrowsePage.Name = "Browse";
                siteAppsGenericContentBrowsePage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>GenericContent Browse App</h1></body></html>"));
                siteAppsGenericContentBrowsePage.Binary.FileName = "1.html";
                siteAppsGenericContentBrowsePage.Save();
            }

            var siteAppsGenericContentEditPage = Node.Load <Page>("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Edit");

            if (siteAppsGenericContentEditPage == null)
            {
                siteAppsGenericContentEditPage      = new Page(siteAppsGenericContentFolder);
                siteAppsGenericContentEditPage.Name = "Edit";
                siteAppsGenericContentEditPage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>GenericContent EditPage</h1></body></html>"));
                siteAppsGenericContentEditPage.Binary.FileName = "1.html";
                siteAppsGenericContentEditPage.Save();
            }


            //---- SelfDispatcher node
            var selfDispatcherContent = Node.Load <GenericContent>("/Root/TestSiteForAppModelTest/Home/SelfDispatcherContent1");

            if (selfDispatcherContent == null)
            {
                selfDispatcherContent      = new GenericContent(homePage, "WebContent");
                selfDispatcherContent.Name = "SelfDispatcherContent1";
                selfDispatcherContent.BrowseApplication = Node.LoadNode("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Edit");
                selfDispatcherContent.Save();
            }
        }
Exemplo n.º 16
0
        private static void DoBenchmarkSteps()
        {
            var root = Node.Load<Folder>("/Root/Timing_TestRoot/STU");
            int id = 0;

            Node n = null;
            for (int i = 0; i < 5; i++)
            {
                n = new GenericContent(root, "Car");
                n.Save();
            }
            id = n.Id;

            Node node;
            for (var i = 0; i < 5; i++)
            {
                for (int j = 0; j < 100; j++)
                {
                    node = Node.LoadNode(id);
                    var sb = new StringBuilder();
                    foreach (var proptype in node.PropertyTypes)
                    {
                        sb.Append(node.GetProperty<object>(proptype));
                    }
                }
                node = Node.LoadNode(id);
                node.Index++;
                node.Save();
            }
        }
Exemplo n.º 17
0
        public void IndexingHistory_FixUpdateDeleteOverlap()
        {
            // update overlaps with delete
            var fieldvalue1 = "IndexingHistoryFixUpdateDeleteOverlap";

            var history = LuceneManager._history;

            var car = new GenericContent(TestRoot, "Car");

            car.Name = Guid.NewGuid().ToString();
            car.Save();
            var id = car.Id;


            // init 1
            var node1 = Node.LoadNode(id);

            node1["Description"] = fieldvalue1;
            node1.Save();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node1.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node1.VersionId);

            var docInfo1  = IndexDocumentInfo.Create(node1, false);
            var docData1  = DataBackingStore.CreateIndexDocumentData(node1, docInfo1, null, null);
            var document1 = IndexDocumentInfo.CreateDocument(docInfo1, docData1);


            // init 2
            var node2 = Node.LoadNode(id);

            node2.ForceDelete();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node2.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node2.VersionId);


            // 1 check indexing history
            var versionId1 = history.GetVersionId(document1);
            var timestamp1 = history.GetTimestamp(document1);
            var historyOk  = LuceneManager._history.CheckForUpdate(versionId1, timestamp1);

            // timestamp in indexing history should be the newest
            var actTimestamp1 = history.Get(versionId1);

            Assert.AreEqual(timestamp1, actTimestamp1, "Timestamp in indexing history did not change.");
            Assert.IsTrue(historyOk, "History indicates indexing should not be executed, but this is not true.");


            // 2 check indexing history
            var versionId2 = node2.VersionId;
            var term       = new Term(LucObject.FieldName.VersionId, Lucene.Net.Util.NumericUtils.IntToPrefixCoded(versionId2));

            LuceneManager._history.ProcessDelete(new Term[] { term });


            // timestamp in indexing history should change
            var actTimestamp2 = history.Get(versionId2);

            Assert.AreEqual(Timestamps.MaxValue, actTimestamp2, "Timestamp in indexing history did not change.");


            // 2 index
            LuceneManager.SetFlagsForDelete(term);
            LuceneManager._writer.DeleteDocuments(term);


            var firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings {
                EnableAutofilters = FilterStatus.Disabled
            }).Count;

            // check indexing occured correctly
            // thread 2 deletes from index
            Assert.AreEqual(0, firstfound);


            // 1 index
            var document   = document1;
            var updateTerm = UpdateDocumentActivity.GetIdTerm(document);

            LuceneManager.SetFlagsForUpdate(document);
            LuceneManager._writer.UpdateDocument(updateTerm, document);

            using (new SenseNet.ContentRepository.Storage.Security.SystemAccount())
                firstfound = ContentQuery.Query(SafeQueries.Description, new QuerySettings {
                    EnableAutofilters = FilterStatus.Disabled
                }, fieldvalue1).Count;

            // check indexing occured correctly
            // thread 1 updates (adds) values to index, ghost document is created
            Assert.AreEqual(1, firstfound);


            // 1 detects problem
            var detectChange1 = history.CheckHistoryChange(versionId1, timestamp1);

            Assert.IsTrue(detectChange1, "Thread 1 did not detect indexing overlapping although it should have.");


            // 1 fixes index
            LuceneManager.RefreshDocument(versionId1, false);

            firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings {
                EnableAutofilters = FilterStatus.Disabled
            }).Count;

            Assert.AreEqual(0, firstfound);
        }
Exemplo n.º 18
0
        public static void CreateSandbox(TestContext testContext)
        {
            var site = Node.Load<Site>("/Root/TestSiteForAppModelTest");
            if (site == null)
            {
                site = new Site(Repository.Root);
                site.Name = "TestSiteForAppModelTest";
                var urlList = new Dictionary<string, string>();
                urlList.Add("testhost", "Windows");
                site.UrlList = urlList;
                site.Save();
            }
            var homePage = EnsureSiteStartPage(site);
            var webContent = Node.Load<GenericContent>("/Root/TestSiteForAppModelTest/Home/WebContent1");
            if (webContent == null)
            {
                webContent = new GenericContent(homePage, "WebContent");
                webContent.Name = "WebContent1";
                webContent.Save();
            }
            var file = Node.Load<File>("/Root/TestSiteForAppModelTest/Home/File1");
            if (file == null)
            {
                file = new File(homePage);
                file.Name = "File1";
                file.GetBinary("Binary").SetStream(Tools.GetStreamFromString("File1 content"));
                file.Save();
            }

            //---- Appmodel

            var siteAppsFolder = Node.Load<SystemFolder>("/Root/TestSiteForAppModelTest/(apps)");
            if (siteAppsFolder == null)
            {
                siteAppsFolder = new SystemFolder(site);
                siteAppsFolder.Name = "(apps)";
                siteAppsFolder.Save();
            }
            var siteAppsPageFolder = Node.Load<Folder>("/Root/TestSiteForAppModelTest/(apps)/Page");
            if (siteAppsPageFolder == null)
            {
                siteAppsPageFolder = new SystemFolder(siteAppsFolder);
                siteAppsPageFolder.Name = "Page";
                siteAppsPageFolder.Save();
            }
            var siteAppsPageBrowsePage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/Page/Browse");
            if (siteAppsPageBrowsePage == null)
            {
                siteAppsPageBrowsePage = new Page(siteAppsPageFolder);
                siteAppsPageBrowsePage.Name = "Browse";
                siteAppsPageBrowsePage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>Page Browse App</h1></body></html>"));
                siteAppsPageBrowsePage.Save();
            }
            var siteAppsPageEditPage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/Page/Edit");
            if (siteAppsPageEditPage == null)
            {
                siteAppsPageEditPage = new Page(siteAppsPageFolder);
                siteAppsPageEditPage.Name = "Edit";
                siteAppsPageEditPage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>Page EditPage</h1></body></html>"));
                siteAppsPageEditPage.Save();
            }

            var siteAppsGenericContentFolder = Node.Load<Folder>("/Root/TestSiteForAppModelTest/(apps)/GenericContent");
            if (siteAppsGenericContentFolder == null)
            {
                siteAppsGenericContentFolder = new SystemFolder(siteAppsFolder);
                siteAppsGenericContentFolder.Name = "GenericContent";
                siteAppsGenericContentFolder.Save();
            }
            var siteAppsGenericContentBrowsePage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Browse");
            if (siteAppsGenericContentBrowsePage == null)
            {
                siteAppsGenericContentBrowsePage = new Page(siteAppsGenericContentFolder);
                siteAppsGenericContentBrowsePage.Name = "Browse";
                siteAppsGenericContentBrowsePage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>GenericContent Browse App</h1></body></html>"));
                siteAppsGenericContentBrowsePage.Save();
            }

            var siteAppsGenericContentEditPage = Node.Load<Page>("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Edit");
            if (siteAppsGenericContentEditPage == null)
            {
                siteAppsGenericContentEditPage = new Page(siteAppsGenericContentFolder);
                siteAppsGenericContentEditPage.Name = "Edit";
                siteAppsGenericContentEditPage.GetBinary("Binary").SetStream(Tools.GetStreamFromString("<html><body><h1>GenericContent EditPage</h1></body></html>"));
                siteAppsGenericContentEditPage.Save();
            }


            //---- SelfDispatcher node
            var selfDispatcherContent = Node.Load<GenericContent>("/Root/TestSiteForAppModelTest/Home/SelfDispatcherContent1");
            if (selfDispatcherContent == null)
            {
                selfDispatcherContent = new GenericContent(homePage, "WebContent");
                selfDispatcherContent.Name = "SelfDispatcherContent1";
                selfDispatcherContent.BrowseApplication = Node.LoadNode("/Root/TestSiteForAppModelTest/(apps)/GenericContent/Edit");
                selfDispatcherContent.Save();
            }
        }
Exemplo n.º 19
0
        public void Storage2_LoadLongText()
        {
            const string longPropertyName = "HTMLFragment";
            var webContent = new GenericContent(TestRoot, "HTMLContent");
            webContent[longPropertyName] = LONG_TEXT1;
            webContent.Save();

            var reloadedText = webContent[longPropertyName] as string;
            
            Assert.IsTrue(!string.IsNullOrEmpty(reloadedText), "New node: Reloaded longtext property is null after save.");
            Assert.AreEqual(LONG_TEXT1, reloadedText, "New node: Reloaded longtext is not the same as the original.");

            webContent = Node.Load<GenericContent>(webContent.Id);

            reloadedText = webContent[longPropertyName] as string;
            Assert.AreEqual(LONG_TEXT1, reloadedText, "Existing node: Reloaded longtext is not the same as the original #1");

            webContent[longPropertyName] = LONG_TEXT2;
            reloadedText = webContent[longPropertyName] as string;
            Assert.AreEqual(LONG_TEXT2, reloadedText, "Existing node: Reloaded longtext is not the same as the original #2");

            webContent.Save();
            webContent = Node.Load<GenericContent>(webContent.Id);
            reloadedText = webContent[longPropertyName] as string;

            Assert.AreEqual(LONG_TEXT2, reloadedText, "Existing node: Reloaded longtext is not the same as the original #3");
        }
Exemplo n.º 20
0
        public void Storage2_CreatePrivateDataOnlyOnDemand()
        {
            var node = new GenericContent(TestRoot, "Car");
            var isShared = node.Data.IsShared;
            var hasShared = node.Data.SharedData != null;
            Assert.IsFalse(isShared, "#1");
            Assert.IsFalse(hasShared, "#2");

            node.Name = Guid.NewGuid().ToString();
            node.Save();
            var id = node.Id;

            //----------------------------------------------

            node = Node.Load<GenericContent>(id);
            isShared = node.Data.IsShared;
            hasShared = node.Data.SharedData != null;
            Assert.IsTrue(isShared, "#3");
            Assert.IsFalse(hasShared, "#4");

            node.Index += 1;

            isShared = node.Data.IsShared;
            hasShared = node.Data.SharedData != null;
            Assert.IsFalse(isShared, "#5");
            Assert.IsTrue(hasShared, "#6");
        }
Exemplo n.º 21
0
        public void IndexingHistory_FixUpdateDeleteOverlap()
        {
            // update overlaps with delete
            var fieldvalue1 = "IndexingHistoryFixUpdateDeleteOverlap";

            var history = LuceneManager._history;

            var car = new GenericContent(TestRoot, "Car");
            car.Name = Guid.NewGuid().ToString();
            car.Save();
            var id = car.Id;


            // init 1
            var node1 = Node.LoadNode(id);
            node1["Description"] = fieldvalue1;
            node1.Save();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node1.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node1.VersionId);

            var docInfo1 = IndexDocumentInfo.Create(node1);
            var docData1 = DataBackingStore.CreateIndexDocumentData(node1, docInfo1, null);
            var document1 = IndexDocumentInfo.CreateDocument(docInfo1, docData1);


            // init 2
            var node2 = Node.LoadNode(id);
            node2.ForceDelete();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node2.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node2.VersionId);


            // 1 check indexing history
            var versionId1 = history.GetVersionId(document1);
            var timestamp1 = history.GetTimestamp(document1);
            var historyOk = LuceneManager._history.CheckForUpdate(versionId1, timestamp1);

            // timestamp in indexing history should be the newest
            var actTimestamp1 = history.Get(versionId1);
            Assert.AreEqual(timestamp1, actTimestamp1, "Timestamp in indexing history did not change.");
            Assert.IsTrue(historyOk, "History indicates indexing should not be executed, but this is not true.");


            // 2 check indexing history
            var versionId2 = node2.VersionId;
            var term = new Term(LucObject.FieldName.VersionId, Lucene.Net.Util.NumericUtils.IntToPrefixCoded(versionId2));
            LuceneManager._history.ProcessDelete(new Term[] { term });


            // timestamp in indexing history should change
            var actTimestamp2 = history.Get(versionId2);
            Assert.AreEqual(long.MaxValue, actTimestamp2, "Timestamp in indexing history did not change.");


            // 2 index
            LuceneManager.SetFlagsForDelete(term);
            LuceneManager._writer.DeleteDocuments(term);


            var firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count;

            // check indexing occured correctly
            // thread 2 deletes from index
            Assert.AreEqual(0, firstfound);


            // 1 index
            var document = document1;
            var updateTerm = UpdateDocumentActivity.GetIdTerm(document);
            LuceneManager.SetFlagsForUpdate(document);
            LuceneManager._writer.UpdateDocument(updateTerm, document);


            firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count;

            // check indexing occured correctly
            // thread 1 updates (adds) values to index, ghost document is created
            Assert.AreEqual(1, firstfound);


            // 1 detects problem
            var detectChange1 = history.CheckHistoryChange(versionId1, timestamp1);
            Assert.IsTrue(detectChange1, "Thread 1 did not detect indexing overlapping although it should have.");


            // 1 fixes index
            LuceneManager.RefreshDocument(versionId1);

            firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count;

            Assert.AreEqual(0, firstfound);
        }
Exemplo n.º 22
0
        public void IndexingHistory_FixAddUpdateOverlap()
        {
            // add overlaps with update
            var fieldvalue1 = "IndexingHistoryFixAddUpdateOverlapFirst";
            var fieldvalue2 = "IndexingHistoryFixAddUpdateOverlapSecond";

            var history = LuceneManager._history;

            var car = new GenericContent(TestRoot, "Car");
            car.Name = Guid.NewGuid().ToString();
            car.Save();
            var id = car.Id;


            // init 1
            var node1 = Node.LoadNode(id);
            node1["Description"] = fieldvalue1;
            node1.Save();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node1.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node1.VersionId);

            var docInfo1 = IndexDocumentInfo.Create(node1);
            var docData1 = DataBackingStore.CreateIndexDocumentData(node1, docInfo1, null);
            var document1 = IndexDocumentInfo.CreateDocument(docInfo1, docData1);


            // init 2
            var node2 = Node.LoadNode(id);
            node2["Description"] = fieldvalue2;
            node2.Save();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node2.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node2.VersionId);

            var docInfo2 = IndexDocumentInfo.Create(node2);
            var docData2 = DataBackingStore.CreateIndexDocumentData(node2, docInfo2, null);
            var document2 = IndexDocumentInfo.CreateDocument(docInfo2, docData2);


            // 1 check indexing history
            var versionId1 = history.GetVersionId(document1);
            var timestamp1 = history.GetTimestamp(document1);
            var historyOk = LuceneManager._history.CheckForAdd(versionId1, timestamp1);

            // timestamp in indexing history should be the newest
            var actTimestamp1 = history.Get(versionId1);
            Assert.AreEqual(timestamp1, actTimestamp1, "Timestamp in indexing history did not change.");
            Assert.IsTrue(historyOk, "History indicates indexing should not be executed, but this is not true.");


            // 2 check indexing history
            var versionId2 = history.GetVersionId(document2);
            var timestamp2 = history.GetTimestamp(document2);
            historyOk = LuceneManager._history.CheckForUpdate(versionId2, timestamp2);


            // timestamp in indexing history should change
            var actTimestamp2 = history.Get(versionId2);
            Assert.AreEqual(timestamp2, actTimestamp2, "Timestamp in indexing history did not change.");
            Assert.IsTrue(historyOk, "History indicates indexing should not be executed, but this is not true.");


            // 2 index
            var document = document2;
            var updateTerm = UpdateDocumentActivity.GetIdTerm(document);
            LuceneManager.SetFlagsForUpdate(document);
            LuceneManager._writer.UpdateDocument(updateTerm, document);


            var firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count;
            var secondfound = ContentQuery.Query("Description:" + fieldvalue2, new QuerySettings { EnableAutofilters = false }).Count;

            // check indexing occured correctly
            // thread 2 writes values in index
            Assert.AreEqual(0, firstfound);
            Assert.AreEqual(1, secondfound);


            // 1 index
            document = document1;
            LuceneManager._writer.AddDocument(document);


            firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count;
            secondfound = ContentQuery.Query("Description:" + fieldvalue2, new QuerySettings { EnableAutofilters = false }).Count;

            // check indexing occured correctly
            // thread 1 adds values to index, duplication occurs
            Assert.AreEqual(1, firstfound);
            Assert.AreEqual(1, secondfound);


            // 1 detects problem
            var detectChange1 = history.CheckHistoryChange(versionId1, timestamp1);
            Assert.IsTrue(detectChange1, "Thread 1 did not detect indexing overlapping although it should have.");

            // 2 detects no problem
            var detectChange2 = history.CheckHistoryChange(versionId2, timestamp2);
            Assert.IsFalse(detectChange2, "Thread 2 detected indexing overlapping although it should not have.");


            // 1 fixes index
            LuceneManager.RefreshDocument(versionId1);

            firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count;
            secondfound = ContentQuery.Query("Description:" + fieldvalue2, new QuerySettings { EnableAutofilters = false }).Count;

            Assert.AreEqual(0, firstfound);
            Assert.AreEqual(1, secondfound);

            var node = Node.LoadNode(id);
            node.ForceDelete();
        }
Exemplo n.º 23
0
        public void IndexingHistory_FixDeleteUpdateOverlap()
        {
            // delete overlaps with update
            var fieldvalue1 = "IndexingHistoryFixDeleteAddOverlap";

            var history = LuceneManager._history;

            var car = new GenericContent(TestRoot, "Car");

            car.Name = Guid.NewGuid().ToString();
            car.Save();
            var id = car.Id;


            // init 2
            var node2 = Node.LoadNode(id);

            node2["Description"] = fieldvalue1;
            node2.Save();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node2.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node2.VersionId);

            var docInfo2  = IndexDocumentInfo.Create(node2, false);
            var docData2  = DataBackingStore.CreateIndexDocumentData(node2, docInfo2, null, null);
            var document2 = IndexDocumentInfo.CreateDocument(docInfo2, docData2);


            // init 1
            var node1 = Node.LoadNode(id);

            node1.ForceDelete();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node1.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node1.VersionId);



            // 1 check indexing history
            var versionId1 = node2.VersionId;
            var term       = new Term(LucObject.FieldName.VersionId, Lucene.Net.Util.NumericUtils.IntToPrefixCoded(versionId1));

            LuceneManager._history.ProcessDelete(new Term[] { term });


            // timestamp in indexing history should change
            var actTimestamp1 = history.Get(versionId1);

            Assert.AreEqual(Timestamps.MaxValue, actTimestamp1, "Timestamp in indexing history did not change.");


            // 2 check indexing history
            var versionId2 = history.GetVersionId(document2);
            var timestamp2 = history.GetTimestamp(document2);
            var historyOk  = LuceneManager._history.CheckForUpdate(versionId2, timestamp2);


            // timestamp in indexing history should not change
            var actTimestamp2 = history.Get(versionId2);

            Assert.AreNotEqual(timestamp2, actTimestamp2, "Timestamp in indexing history changed, although it should not have.");
            Assert.IsFalse(historyOk, "History indicates indexing can be executed, but this is not true.");

            // 2 does not continue, returns

            // 1 deletes index
            LuceneManager.SetFlagsForDelete(term);
            LuceneManager._writer.DeleteDocuments(term);


            var firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings {
                EnableAutofilters = FilterStatus.Disabled
            }).Count;

            // check indexing occured correctly
            // thread 1 deletes from index
            Assert.AreEqual(0, firstfound);
        }
Exemplo n.º 24
0
        public void ContentList_DeleteField()
        {
            string listDef = @"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<DisplayName>Cars title</DisplayName>
	<Description>Cars description</Description>
	<Icon>automobile.gif</Icon>
	<Fields>
		<ContentListField name='#ListField1' type='ShortText'>
			<DisplayName>ContentListField1</DisplayName>
			<Description>ContentListField1 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
				<MaxLength>100</MaxLength>
			</Configuration>
		</ContentListField>
		<ContentListField name='#ListField2' type='WhoAndWhen'>
			<DisplayName>ContentListField2</DisplayName>
			<Description>ContentListField2 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
			</Configuration>
		</ContentListField>
		<ContentListField name='#ListField3' type='ShortText'>
			<DisplayName>ContentListField3</DisplayName>
			<Description>ContentListField3 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
				<MaxLength>200</MaxLength>
			</Configuration>
		</ContentListField>
	</Fields>
</ContentListDefinition>
";
            string path    = RepositoryPath.Combine(this.TestRoot.Path, "Cars");

            if (Node.Exists(path))
            {
                Node.ForceDelete(path);
            }

            var list = new ContentList(this.TestRoot)
            {
                Name = "Cars",
                ContentListDefinition = listDef,
                AllowedChildTypes     = new ContentType[] { ContentType.GetByName("Car") }
            };

            list.Save();

            Node car = new GenericContent(list, "Car");

            car.Name         = "Kispolszki";
            car["#String_0"] = "ABC 34-78";
            car.Save();

            list = Node.Load <ContentList>(list.Path);
            var fs = Content.Create(car).Fields["#ListField3"].FieldSetting;

            list.DeleteField(fs);

            var cc = Content.Load(car.Path);

            Assert.IsTrue(!cc.Fields.ContainsKey("#ListField3"));
        }
Exemplo n.º 25
0
        public void IndexingHistory_FixAddAddOverlap()
        {
            // add overlaps with add
            var fieldvalue1 = "IndexingHistoryFixAddAddOverlap";

            var history = LuceneManager._history;

            var car = new GenericContent(TestRoot, "Car");

            car.Name = Guid.NewGuid().ToString();
            car.Save();
            var id = car.Id;


            // init 1 & 2
            var node1 = Node.LoadNode(id);

            node1["Description"] = fieldvalue1;
            node1.Save();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node1.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node1.VersionId);

            var docInfo1  = IndexDocumentInfo.Create(node1, false);
            var docData1  = DataBackingStore.CreateIndexDocumentData(node1, docInfo1, null, null);
            var document1 = IndexDocumentInfo.CreateDocument(docInfo1, docData1);


            // 1 check indexing history
            var versionId1 = history.GetVersionId(document1);
            var timestamp1 = history.GetTimestamp(document1);
            var historyOk  = LuceneManager._history.CheckForAdd(versionId1, timestamp1);

            // timestamp in indexing history should be the newest
            var actTimestamp1 = history.Get(versionId1);

            Assert.AreEqual(timestamp1, actTimestamp1, "Timestamp in indexing history did not change.");
            Assert.IsTrue(historyOk, "History indicates indexing should not be executed, but this is not true.");


            // 2 check indexing history
            var versionId2 = history.GetVersionId(document1);
            var timestamp2 = history.GetTimestamp(document1);

            historyOk = LuceneManager._history.CheckForAdd(versionId2, timestamp2);


            // timestamp in indexing history should not change
            var actTimestamp2 = history.Get(versionId2);

            Assert.AreEqual(timestamp2, actTimestamp2, "Timestamp in indexing history changed, although it should not have.");
            Assert.IsFalse(historyOk, "History indicates indexing can be executed, but this is not true.");

            // 2 does not continue, returns

            // 1 index
            var document = document1;

            LuceneManager._writer.AddDocument(document);


            var firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings {
                EnableAutofilters = FilterStatus.Disabled
            }).Count;

            // check indexing occured correctly
            // thread 1 adds values to index
            Assert.AreEqual(1, firstfound);

            // 1 detects no problem
            var detectChange1 = history.CheckHistoryChange(versionId1, timestamp1);

            Assert.IsFalse(detectChange1, "Thread 1 detected indexing overlapping although it should not have.");


            var node = Node.LoadNode(id);

            node.ForceDelete();
        }
Exemplo n.º 26
0
        public void ContentList_Modify()
        {
            List <string> listDefs = new List <string>();

            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<Fields>
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF1' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<Fields>
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF1' type='ShortText' />
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF1' type='ShortText' />
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF3' type='ShortText' />
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");
            listDefs.Add(@"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.com/ContentRepository/ContentListDefinition'>
	<Fields>
		<ContentListField name='#LF0' type='ShortText' />
		<ContentListField name='#LF1' type='ShortText' />
		<ContentListField name='#LF2' type='ShortText' />
	</Fields>
</ContentListDefinition>
");

            string listName = "List1";
            string listPath = RepositoryPath.Combine(this.TestRoot.Path, listName);

            if (Node.Exists(listPath))
            {
                Node.ForceDelete(listPath);
            }

            ContentList list = new ContentList(this.TestRoot);

            list.Name = listName;
            list.AllowedChildTypes = new ContentType[] { ContentType.GetByName("Car") };

            list.Save();

            Node car = new GenericContent(list, "Car");

            car.Name = "Kispolszki";
            car.Save();
            int carId = car.Id;

            StringBuilder log = new StringBuilder();

            for (int def = 0; def < listDefs.Count; def++)
            {
                Exception ex = null;
                for (var i = 0; i < 10; i++)
                {
                    try
                    {
                        ex   = null;
                        list = Node.Load <ContentList>(listPath);
                        list.ContentListDefinition = listDefs[def];
                        list.Save();
                        break;
                    }
                    catch (Exception e)
                    {
                        ex = e;
                        System.Threading.Thread.Sleep(200);
                        Debug.WriteLine("@> {0}. {1} / {2}", i, def, listDefs.Count);
                    }
                }
                if (ex != null)
                {
                    throw new ApplicationException("Exception after 10 iteration: " + ex.Message, ex);
                }


                car = Node.LoadNode(carId);
                log.Append("Def_").Append(def).Append(": ");
                for (int i = 0; i < 4; i++)
                {
                    var propName = "#String_" + i;
                    if (car.HasProperty(propName))
                    {
                        log.Append("[").Append(propName).Append(" = ").Append(car.PropertyTypes[propName].Mapping).Append("]");
                    }
                }
                log.Append("\r\n");
            }

            string realLog     = log.Replace("\r\n", "").Replace(" ", "").Replace("\t", "").ToString();
            string expectedLog = @"
				Def_0: 
				Def_1: [#String_0 = 800000000][#String_1 = 800000001]
				Def_2: [#String_0 = 800000000]
				Def_3: 
				Def_4: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002]
				Def_5: [#String_0 = 800000000][#String_2 = 800000002]
				Def_6: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002]
				Def_7: [#String_2 = 800000002]
				Def_8: [#String_0 = 800000000][#String_1 = 800000001][#String_2 = 800000002]
				Def_9: [#String_0 = 800000000][#String_2 = 800000002][#String_3 = 800000003]
				"                .Replace("\r\n", "").Replace(" ", "").Replace("\t", "");

            Assert.IsTrue(realLog == expectedLog);
        }
Exemplo n.º 27
0
		public void ContentList_1()
		{
			string listDef = @"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<DisplayName>Cars title</DisplayName>
	<Description>Cars description</Description>
	<Icon>automobile.gif</Icon>
	<Fields>
		<ContentListField name='#ListField1' type='ShortText'>
			<DisplayName>ContentListField1</DisplayName>
			<Description>ContentListField1 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
				<MaxLength>100</MaxLength>
			</Configuration>
		</ContentListField>
		<ContentListField name='#ListField2' type='WhoAndWhen'>
			<DisplayName>ContentListField2</DisplayName>
			<Description>ContentListField2 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
			</Configuration>
		</ContentListField>
		<ContentListField name='#ListField3' type='ShortText'>
			<DisplayName>ContentListField3</DisplayName>
			<Description>ContentListField3 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
				<MaxLength>200</MaxLength>
			</Configuration>
		</ContentListField>
	</Fields>
</ContentListDefinition>
";
			string path = RepositoryPath.Combine(this.TestRoot.Path, "Cars");
			if (Node.Exists(path))
                Node.ForceDelete(path);

			ContentList list = new ContentList(this.TestRoot);
            list.Name = "Cars";
            list.ContentListDefinition = listDef;
            list.AllowedChildTypes = new ContentType[] { ContentType.GetByName("Car") };

            list.Save();

            Node car = new GenericContent(list, "Car");
			car.Name = "Kispolszki";
			car["#String_0"] = "ABC 34-78";
			car.Save();

			Content content = Content.Create(car);

			//-- Sikeres, ha nem dob hibat
		}
Exemplo n.º 28
0
        public void ContentList_DeleteField()
        {
            string listDef = @"<?xml version='1.0' encoding='utf-8'?>
<ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	<DisplayName>Cars title</DisplayName>
	<Description>Cars description</Description>
	<Icon>automobile.gif</Icon>
	<Fields>
		<ContentListField name='#ListField1' type='ShortText'>
			<DisplayName>ContentListField1</DisplayName>
			<Description>ContentListField1 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
				<MaxLength>100</MaxLength>
			</Configuration>
		</ContentListField>
		<ContentListField name='#ListField2' type='WhoAndWhen'>
			<DisplayName>ContentListField2</DisplayName>
			<Description>ContentListField2 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
			</Configuration>
		</ContentListField>
		<ContentListField name='#ListField3' type='ShortText'>
			<DisplayName>ContentListField3</DisplayName>
			<Description>ContentListField3 Description</Description>
			<Icon>icon.gif</Icon>
			<Configuration>
				<MaxLength>200</MaxLength>
			</Configuration>
		</ContentListField>
	</Fields>
</ContentListDefinition>
";
            string path = RepositoryPath.Combine(this.TestRoot.Path, "Cars");
            if (Node.Exists(path))
                Node.ForceDelete(path);

            var list = new ContentList(this.TestRoot)
            {
                Name = "Cars",
                ContentListDefinition = listDef,
                AllowedChildTypes = new ContentType[] { ContentType.GetByName("Car") }
            };

            list.Save();

            Node car = new GenericContent(list, "Car");
            car.Name = "Kispolszki";
            car["#String_0"] = "ABC 34-78";
            car.Save();

            list = Node.Load<ContentList>(list.Path);
            var fs = Content.Create(car).Fields["#ListField3"].FieldSetting;

            list.DeleteField(fs);

            var cc = Content.Load(car.Path);

            Assert.IsTrue(!cc.Fields.ContainsKey("#ListField3"));
        }
Exemplo n.º 29
0
        public void ContentList_WithoutDefinition()
		{
			string path = RepositoryPath.Combine(this.TestRoot.Path, "Cars");
			if (Node.Exists(path))
                Node.ForceDelete(path);

            ContentList list = new ContentList(this.TestRoot);
            list.Name = "Cars";
            list.AllowedChildTypes = new ContentType[] { ContentType.GetByName("Car") };

            list.Save();

            Node car = new GenericContent(list, "Car");
			car.Name = "Kispolszki";
			car.Save();

			//-- Sikeres, ha nem dob hibat
		}
Exemplo n.º 30
0
        public void ContentList_Concurrent_AddStringField()
        {
            string listDef0 = @"<?xml version='1.0' encoding='utf-8'?>
                <ContentListDefinition xmlns='http://schemas.sensenet.com/SenseNet/ContentRepository/ContentListDefinition'>
	                <Fields>
		                <ContentListField name='#StringField1' type='ShortText' />
	                </Fields>
                </ContentListDefinition>
                ";

            string path = RepositoryPath.Combine(this.TestRoot.Path, "Cars");
            if (Node.Exists(path))
                Node.ForceDelete(path);

            var list = new ContentList(this.TestRoot);
            list.Name = "Cars";
            list.ContentListDefinition = listDef0;
            list.AllowedChildTypes = new ContentType[] { ContentType.GetByName("Car") };

            list.Save();
            var listId = list.Id;

            Node car = new GenericContent(list, "Car");
            car.Name = "Trabant Tramp";
            car["#String_0"] = "ABC 34-78";
            car.Save();

            var t1 = new System.Threading.Thread(ContentList_Concurrent_AddStringField_Thread);
            var t2 = new System.Threading.Thread(ContentList_Concurrent_AddStringField_Thread);
            t1.Start();
            t2.Start();

            var startingTime = DateTime.Now;
            while (counter < 2)
            {
                System.Threading.Thread.Sleep(1000);
                if ((DateTime.Now - startingTime).TotalSeconds > 10)
                    break;
            }
            if (t1.ThreadState == System.Threading.ThreadState.Running)
                t1.Abort();
            if (t2.IsAlive)
                t2.Abort();

            Assert.IsTrue(counter == 2);
        }
Exemplo n.º 31
0
        public void IndexingHistory_FixAddAddOverlap()
        {
            // add overlaps with add
            var fieldvalue1 = "IndexingHistoryFixAddAddOverlap";

            var history = LuceneManager._history;

            var car = new GenericContent(TestRoot, "Car");
            car.Name = Guid.NewGuid().ToString();
            car.Save();
            var id = car.Id;


            // init 1 & 2
            var node1 = Node.LoadNode(id);
            node1["Description"] = fieldvalue1;
            node1.Save();
            // delete changes from index
            DataRowTimestampTest.DeleteVersionFromIndex(node1.VersionId);
            DataRowTimestampTest.DeleteVersionIdFromIndexingHistory(node1.VersionId);

            var docInfo1 = IndexDocumentInfo.Create(node1);
            var docData1 = DataBackingStore.CreateIndexDocumentData(node1, docInfo1, null);
            var document1 = IndexDocumentInfo.CreateDocument(docInfo1, docData1);


            // 1 check indexing history
            var versionId1 = history.GetVersionId(document1);
            var timestamp1 = history.GetTimestamp(document1);
            var historyOk = LuceneManager._history.CheckForAdd(versionId1, timestamp1);

            // timestamp in indexing history should be the newest
            var actTimestamp1 = history.Get(versionId1);
            Assert.AreEqual(timestamp1, actTimestamp1, "Timestamp in indexing history did not change.");
            Assert.IsTrue(historyOk, "History indicates indexing should not be executed, but this is not true.");


            // 2 check indexing history
            var versionId2 = history.GetVersionId(document1);
            var timestamp2 = history.GetTimestamp(document1);
            historyOk = LuceneManager._history.CheckForAdd(versionId2, timestamp2);


            // timestamp in indexing history should not change
            var actTimestamp2 = history.Get(versionId2);
            Assert.AreEqual(timestamp2, actTimestamp2, "Timestamp in indexing history changed, although it should not have.");
            Assert.IsFalse(historyOk, "History indicates indexing can be executed, but this is not true.");

            // 2 does not continue, returns

            // 1 index
            var document = document1;
            LuceneManager._writer.AddDocument(document);


            var firstfound = ContentQuery.Query("Description:" + fieldvalue1, new QuerySettings { EnableAutofilters = false }).Count;

            // check indexing occured correctly
            // thread 1 adds values to index
            Assert.AreEqual(1, firstfound);

            // 1 detects no problem
            var detectChange1 = history.CheckHistoryChange(versionId1, timestamp1);
            Assert.IsFalse(detectChange1, "Thread 1 detected indexing overlapping although it should not have.");


            var node = Node.LoadNode(id);
            node.ForceDelete();
        }