30
30
import java .util .LinkedList ;
31
31
import java .util .List ;
32
32
import junit .framework .TestCase ;
33
+ import org .opensolaris .opengrok .configuration .RuntimeEnvironment ;
33
34
import org .opensolaris .opengrok .util .Executor ;
34
35
import org .opensolaris .opengrok .util .TestRepository ;
35
36
@@ -86,6 +87,7 @@ private void importHgChangeset(File reposRoot, String changesetFile) {
86
87
* Assert that two HistoryEntry objects are equal.
87
88
* @param expected the expected entry
88
89
* @param actual the actual entry
90
+ * @param isdir was the history generated for a directory
89
91
* @throws AssertFailure if the two entries don't match
90
92
*/
91
93
private void assertSameEntries (
@@ -102,6 +104,7 @@ private void assertSameEntries(
102
104
* Assert that two lists of HistoryEntry objects are equal.
103
105
* @param expected the expected list of entries
104
106
* @param actual the actual list of entries
107
+ * @param isdir was the history generated for directory
105
108
* @throws AssertFailure if the two lists don't match
106
109
*/
107
110
private void assertSameEntry (HistoryEntry expected , HistoryEntry actual , boolean isdir ) {
@@ -114,8 +117,9 @@ private void assertSameEntry(HistoryEntry expected, HistoryEntry actual, boolean
114
117
} else {
115
118
assertEquals (0 , actual .getFiles ().size ());
116
119
}
120
+ assertEquals (expected .getTags (), actual .getTags ());
117
121
}
118
-
122
+
119
123
/**
120
124
* Basic tests for the {@code store()} method on cache with disabled
121
125
* handling of renamed files.
@@ -138,6 +142,83 @@ public void testStoreAndGetNotRenamed() throws Exception {
138
142
assertEquals ("9:8b340409b3a8" , cache .getLatestCachedRevision (repo ));
139
143
}
140
144
145
+ /**
146
+ * Test tagging by creating history cache for repository with one tag
147
+ * and then importing couple of changesets which add both file changes
148
+ * and tags. The last history entry before the import is important
149
+ * as it needs to be retagged when old history is merged with the new one.
150
+ */
151
+ public void testStoreAndGetIncrementalTags () throws Exception {
152
+ // Enable tagging of history entries.
153
+ RuntimeEnvironment .getInstance ().setTagsEnabled (true );
154
+
155
+ File reposRoot = new File (repositories .getSourceRoot (), "mercurial" );
156
+ Repository repo = RepositoryFactory .getRepository (reposRoot );
157
+ History historyToStore = repo .getHistory (reposRoot );
158
+
159
+ // Store the history.
160
+ cache .store (historyToStore , repo );
161
+
162
+ // Add bunch of changesets with file based changes and tags.
163
+ importHgChangeset (
164
+ reposRoot , getClass ().getResource ("hg-export-tag.txt" ).getPath ());
165
+
166
+ // Perform incremental reindex.
167
+ repo .createCache (cache , cache .getLatestCachedRevision (repo ));
168
+
169
+ // Check that the changesets were indeed applied and indexed.
170
+ History updatedHistory = cache .get (reposRoot , repo , true );
171
+ assertEquals ("Unexpected number of history entries" ,
172
+ 15 , updatedHistory .getHistoryEntries ().size ());
173
+
174
+ // Verify tags in fileHistory for main.c which is the most interesting
175
+ // file from the repository from the perspective of tags.
176
+ File main = new File (reposRoot , "main.c" );
177
+ assertTrue (main .exists ());
178
+ History retrievedHistoryMainC = cache .get (main , repo , true );
179
+ List <HistoryEntry > entries = retrievedHistoryMainC .getHistoryEntries ();
180
+ assertEquals ("Unexpected number of entries for main.c" ,
181
+ 3 , entries .size ());
182
+ HistoryEntry e0 = entries .get (0 );
183
+ assertEquals ("Unexpected revision for entry 0" , "13:3d386f6bd848" ,
184
+ e0 .getRevision ());
185
+ assertEquals ("Invalid tag list for revision 13" , "tag3" , e0 .getTags ());
186
+ HistoryEntry e1 = entries .get (1 );
187
+ assertEquals ("Unexpected revision for entry 1" , "2:585a1b3f2efb" ,
188
+ e1 .getRevision ());
189
+ assertEquals ("Invalid tag list for revision 2" ,
190
+ "tag2, tag1, start_of_novel" , e1 .getTags ());
191
+ HistoryEntry e2 = entries .get (2 );
192
+ assertEquals ("Unexpected revision for entry 2" , "1:f24a5fd7a85d" ,
193
+ e2 .getRevision ());
194
+ assertEquals ("Invalid tag list for revision 1" , null , e2 .getTags ());
195
+
196
+ // Reindex from scratch.
197
+ File dir = new File (cache .getRepositoryHistDataDirname (repo ));
198
+ assertTrue (dir .isDirectory ());
199
+ cache .clear (repo );
200
+ // We cannot call cache.get() here since it would read the history anew.
201
+ // Instead check that the data directory does not exist anymore.
202
+ assertFalse (dir .exists ());
203
+ History freshHistory = repo .getHistory (reposRoot );
204
+ cache .store (freshHistory , repo );
205
+ History updatedHistoryFromScratch = cache .get (reposRoot , repo , true );
206
+ assertEquals ("Unexpected number of history entries" ,
207
+ freshHistory .getHistoryEntries ().size (),
208
+ updatedHistoryFromScratch .getHistoryEntries ().size ());
209
+
210
+ // Verify that the result for the directory is the same as incremental
211
+ // reindex.
212
+ assertSameEntries (updatedHistory .getHistoryEntries (),
213
+ updatedHistoryFromScratch .getHistoryEntries (), true );
214
+ // Do the same for main.c.
215
+ History retrievedUpdatedHistoryMainC = cache .get (main , repo , true );
216
+ assertSameEntries (retrievedHistoryMainC .getHistoryEntries (),
217
+ retrievedUpdatedHistoryMainC .getHistoryEntries (), false );
218
+
219
+ RuntimeEnvironment .getInstance ().setTagsEnabled (false );
220
+ }
221
+
141
222
/**
142
223
* Basic tests for the {@code store()} and {@code get()} methods.
143
224
*/
0 commit comments