Line data Source code
1 : // Copyright (C) 2017 The Android Open Source Project 2 : // 3 : // Licensed under the Apache License, Version 2.0 (the "License"); 4 : // you may not use this file except in compliance with the License. 5 : // You may obtain a copy of the License at 6 : // 7 : // http://www.apache.org/licenses/LICENSE-2.0 8 : // 9 : // Unless required by applicable law or agreed to in writing, software 10 : // distributed under the License is distributed on an "AS IS" BASIS, 11 : // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 : // See the License for the specific language governing permissions and 13 : // limitations under the License. 14 : 15 : package com.google.gerrit.acceptance; 16 : 17 : import com.google.gerrit.entities.Change; 18 : import com.google.gerrit.index.QueryOptions; 19 : import com.google.gerrit.index.Schema; 20 : import com.google.gerrit.index.query.DataSource; 21 : import com.google.gerrit.index.query.Predicate; 22 : import com.google.gerrit.index.query.QueryParseException; 23 : import com.google.gerrit.server.index.change.ChangeIndex; 24 : import com.google.gerrit.server.query.change.ChangeData; 25 : import java.util.Optional; 26 : 27 : /** 28 : * This class wraps an index and assumes the search index can't handle any queries. However, it does 29 : * return the current schema as the assumption is that we need a search index for starting Gerrit in 30 : * the first place and only later lose the index connection (making it so that we can't send 31 : * requests there anymore). 32 : */ 33 : public class DisabledChangeIndex implements ChangeIndex { 34 : private final ChangeIndex index; 35 : 36 8 : public DisabledChangeIndex(ChangeIndex index) { 37 8 : this.index = index; 38 8 : } 39 : 40 : public ChangeIndex unwrap() { 41 8 : return index; 42 : } 43 : 44 : @Override 45 : public Schema<ChangeData> getSchema() { 46 8 : return index.getSchema(); 47 : } 48 : 49 : @Override 50 : public void close() { 51 0 : index.close(); 52 0 : } 53 : 54 : @Override 55 : public void insert(ChangeData obj) { 56 0 : throw new UnsupportedOperationException("ChangeIndex is disabled"); 57 : } 58 : 59 : @Override 60 : public void replace(ChangeData obj) { 61 3 : throw new UnsupportedOperationException("ChangeIndex is disabled"); 62 : } 63 : 64 : @Override 65 : public void delete(Change.Id key) { 66 0 : throw new UnsupportedOperationException("ChangeIndex is disabled"); 67 : } 68 : 69 : @Override 70 : public void deleteAll() { 71 0 : throw new UnsupportedOperationException("ChangeIndex is disabled"); 72 : } 73 : 74 : @Override 75 : public DataSource<ChangeData> getSource(Predicate<ChangeData> p, QueryOptions opts) 76 : throws QueryParseException { 77 1 : throw new UnsupportedOperationException("ChangeIndex is disabled"); 78 : } 79 : 80 : @Override 81 : public void markReady(boolean ready) { 82 0 : throw new UnsupportedOperationException("ChangeIndex is disabled"); 83 : } 84 : 85 : @Override 86 : public Optional<ChangeData> get(Change.Id key, QueryOptions opts) { 87 0 : throw new UnsupportedOperationException("ChangeIndex is disabled"); 88 : } 89 : }