You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by jp...@apache.org on 2014/09/01 14:21:01 UTC
svn commit: r1621756 - in
/lucene/dev/branches/lucene5858/lucene/backward-codecs/src/test/org/apache/lucene/index:
TestDisableImpersonation.java TestDocValuesUpdatesOnOldSegments.java
Author: jpountz
Date: Mon Sep 1 12:21:00 2014
New Revision: 1621756
URL: http://svn.apache.org/r1621756
Log:
LUCENE-5858: Add missing files.
Added:
lucene/dev/branches/lucene5858/lucene/backward-codecs/src/test/org/apache/lucene/index/TestDisableImpersonation.java (with props)
lucene/dev/branches/lucene5858/lucene/backward-codecs/src/test/org/apache/lucene/index/TestDocValuesUpdatesOnOldSegments.java (with props)
Added: lucene/dev/branches/lucene5858/lucene/backward-codecs/src/test/org/apache/lucene/index/TestDisableImpersonation.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5858/lucene/backward-codecs/src/test/org/apache/lucene/index/TestDisableImpersonation.java?rev=1621756&view=auto
==============================================================================
--- lucene/dev/branches/lucene5858/lucene/backward-codecs/src/test/org/apache/lucene/index/TestDisableImpersonation.java (added)
+++ lucene/dev/branches/lucene5858/lucene/backward-codecs/src/test/org/apache/lucene/index/TestDisableImpersonation.java Mon Sep 1 12:21:00 2014
@@ -0,0 +1,62 @@
+package org.apache.lucene.index;
+
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.codecs.lucene40.Lucene40RWCodec;
+import org.apache.lucene.codecs.lucene41.Lucene41RWCodec;
+import org.apache.lucene.codecs.lucene42.Lucene42RWCodec;
+import org.apache.lucene.codecs.lucene45.Lucene45RWCodec;
+import org.apache.lucene.codecs.lucene46.Lucene46RWCodec;
+import org.apache.lucene.codecs.lucene49.Lucene49RWCodec;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.NumericDocValuesField;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.LuceneTestCase;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+public class TestDisableImpersonation extends LuceneTestCase {
+
+ public void testDisableImpersonation() throws Exception {
+ Codec[] oldCodecs = new Codec[] { new Lucene40RWCodec(), new Lucene41RWCodec(), new Lucene42RWCodec(), new Lucene45RWCodec(), new Lucene46RWCodec(), new Lucene49RWCodec() };
+ Directory dir = newDirectory();
+ IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
+ conf.setCodec(oldCodecs[random().nextInt(oldCodecs.length)]);
+ IndexWriter writer = new IndexWriter(dir, conf);
+
+ Document doc = new Document();
+ doc.add(new StringField("f", "bar", Store.YES));
+ doc.add(new NumericDocValuesField("n", 18L));
+
+ OLD_FORMAT_IMPERSONATION_IS_ACTIVE = false;
+ try {
+ writer.addDocument(doc);
+ writer.close();
+ fail("should not have succeeded to impersonate an old format!");
+ } catch (UnsupportedOperationException e) {
+ writer.rollback();
+ } finally {
+ OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
+ }
+
+ dir.close();
+ }
+
+}
Added: lucene/dev/branches/lucene5858/lucene/backward-codecs/src/test/org/apache/lucene/index/TestDocValuesUpdatesOnOldSegments.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5858/lucene/backward-codecs/src/test/org/apache/lucene/index/TestDocValuesUpdatesOnOldSegments.java?rev=1621756&view=auto
==============================================================================
--- lucene/dev/branches/lucene5858/lucene/backward-codecs/src/test/org/apache/lucene/index/TestDocValuesUpdatesOnOldSegments.java (added)
+++ lucene/dev/branches/lucene5858/lucene/backward-codecs/src/test/org/apache/lucene/index/TestDocValuesUpdatesOnOldSegments.java Mon Sep 1 12:21:00 2014
@@ -0,0 +1,125 @@
+package org.apache.lucene.index;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.codecs.Codec;
+import org.apache.lucene.codecs.lucene40.Lucene40RWCodec;
+import org.apache.lucene.codecs.lucene41.Lucene41RWCodec;
+import org.apache.lucene.codecs.lucene42.Lucene42RWCodec;
+import org.apache.lucene.codecs.lucene45.Lucene45RWCodec;
+import org.apache.lucene.document.BinaryDocValuesField;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.NumericDocValuesField;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.store.Directory;
+import org.apache.lucene.util.BytesRef;
+import org.apache.lucene.util.LuceneTestCase;
+
+
+public class TestDocValuesUpdatesOnOldSegments extends LuceneTestCase {
+
+ static long getValue(BinaryDocValues bdv, int idx) {
+ BytesRef term = bdv.get(idx);
+ idx = term.offset;
+ byte b = term.bytes[idx++];
+ long value = b & 0x7FL;
+ for (int shift = 7; (b & 0x80L) != 0; shift += 7) {
+ b = term.bytes[idx++];
+ value |= (b & 0x7FL) << shift;
+ }
+ return value;
+ }
+
+ // encodes a long into a BytesRef as VLong so that we get varying number of bytes when we update
+ static BytesRef toBytes(long value) {
+ BytesRef bytes = new BytesRef(10); // negative longs may take 10 bytes
+ while ((value & ~0x7FL) != 0L) {
+ bytes.bytes[bytes.length++] = (byte) ((value & 0x7FL) | 0x80L);
+ value >>>= 7;
+ }
+ bytes.bytes[bytes.length++] = (byte) value;
+ return bytes;
+ }
+
+ public void testBinaryUpdates() throws Exception {
+ Codec[] oldCodecs = new Codec[] { new Lucene40RWCodec(), new Lucene41RWCodec(), new Lucene42RWCodec(), new Lucene45RWCodec() };
+ Directory dir = newDirectory();
+
+ boolean oldValue = OLD_FORMAT_IMPERSONATION_IS_ACTIVE;
+ // create a segment with an old Codec
+ IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
+ conf.setCodec(oldCodecs[random().nextInt(oldCodecs.length)]);
+ OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
+ IndexWriter writer = new IndexWriter(dir, conf);
+ Document doc = new Document();
+ doc.add(new StringField("id", "doc", Store.NO));
+ doc.add(new BinaryDocValuesField("f", toBytes(5L)));
+ writer.addDocument(doc);
+ writer.close();
+
+ conf = newIndexWriterConfig(new MockAnalyzer(random()));
+ writer = new IndexWriter(dir, conf);
+ writer.updateBinaryDocValue(new Term("id", "doc"), "f", toBytes(4L));
+ OLD_FORMAT_IMPERSONATION_IS_ACTIVE = false;
+ try {
+ writer.close();
+ fail("should not have succeeded to update a segment written with an old Codec");
+ } catch (UnsupportedOperationException e) {
+ writer.rollback();
+ } finally {
+ OLD_FORMAT_IMPERSONATION_IS_ACTIVE = oldValue;
+ }
+
+ dir.close();
+ }
+
+ public void testNumericUpdates() throws Exception {
+ Codec[] oldCodecs = new Codec[] { new Lucene40RWCodec(), new Lucene41RWCodec(), new Lucene42RWCodec(), new Lucene45RWCodec() };
+ Directory dir = newDirectory();
+
+ boolean oldValue = OLD_FORMAT_IMPERSONATION_IS_ACTIVE;
+ // create a segment with an old Codec
+ IndexWriterConfig conf = newIndexWriterConfig(new MockAnalyzer(random()));
+ conf.setCodec(oldCodecs[random().nextInt(oldCodecs.length)]);
+ OLD_FORMAT_IMPERSONATION_IS_ACTIVE = true;
+ IndexWriter writer = new IndexWriter(dir, conf);
+ Document doc = new Document();
+ doc.add(new StringField("id", "doc", Store.NO));
+ doc.add(new NumericDocValuesField("f", 5));
+ writer.addDocument(doc);
+ writer.close();
+
+ conf = newIndexWriterConfig(new MockAnalyzer(random()));
+ writer = new IndexWriter(dir, conf);
+ writer.updateNumericDocValue(new Term("id", "doc"), "f", 4L);
+ OLD_FORMAT_IMPERSONATION_IS_ACTIVE = false;
+ try {
+ writer.close();
+ fail("should not have succeeded to update a segment written with an old Codec");
+ } catch (UnsupportedOperationException e) {
+ writer.rollback();
+ } finally {
+ OLD_FORMAT_IMPERSONATION_IS_ACTIVE = oldValue;
+ }
+
+ dir.close();
+ }
+
+}