Allow tests to create stale changes
Some operations fail if a change in the index is stale. E.g. the GetRelated REST endpoint fails with 500 Internal Server Error if the change in the index doesn't contain the latest patch set. To be able to test such situations AbstractDaemonTest provides new methods to disable/enable change index writes. A test can now create a stale change by disabling change index writes, updating the change without reindex and then re-enabling change index writes. Change-Id: Ia3b1904162c0ed5de6ecb6229d3995f31606d004 Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
		| @@ -74,6 +74,8 @@ import com.google.gerrit.server.config.GerritServerConfig; | ||||
| import com.google.gerrit.server.git.GitRepositoryManager; | ||||
| import com.google.gerrit.server.git.MetaDataUpdate; | ||||
| import com.google.gerrit.server.git.ProjectConfig; | ||||
| import com.google.gerrit.server.index.change.ChangeIndex; | ||||
| import com.google.gerrit.server.index.change.ChangeIndexCollection; | ||||
| import com.google.gerrit.server.index.change.ChangeIndexer; | ||||
| import com.google.gerrit.server.mail.EmailHeader; | ||||
| import com.google.gerrit.server.notedb.ChangeNoteUtil; | ||||
| @@ -221,6 +223,9 @@ public abstract class AbstractDaemonTest { | ||||
|   @Inject | ||||
|   private EventRecorder.Factory eventRecorderFactory; | ||||
|  | ||||
|   @Inject | ||||
|   private ChangeIndexCollection changeIndexes; | ||||
|  | ||||
|   protected TestRepository<InMemoryRepository> testRepo; | ||||
|   protected GerritServer server; | ||||
|   protected TestAccount admin; | ||||
| @@ -673,6 +678,22 @@ public abstract class AbstractDaemonTest { | ||||
|     atrScope.set(preDisableContext); | ||||
|   } | ||||
|  | ||||
|   protected void disableChangeIndexWrites() { | ||||
|     for (ChangeIndex i : changeIndexes.getWriteIndexes()) { | ||||
|       if (!(i instanceof ReadOnlyChangeIndex)) { | ||||
|         changeIndexes.addWriteIndex(new ReadOnlyChangeIndex(i)); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   protected void enableChangeIndexWrites() { | ||||
|     for (ChangeIndex i : changeIndexes.getWriteIndexes()) { | ||||
|       if (i instanceof ReadOnlyChangeIndex) { | ||||
|         changeIndexes.addWriteIndex(((ReadOnlyChangeIndex)i).unwrap()); | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   protected static Gson newGson() { | ||||
|     return OutputFormat.JSON_COMPACT.newGson(); | ||||
|   } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Edwin Kempin
					Edwin Kempin