Return-Path: X-Original-To: apmail-geode-commits-archive@minotaur.apache.org Delivered-To: apmail-geode-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8632D183FE for ; Fri, 13 Nov 2015 05:32:18 +0000 (UTC) Received: (qmail 18752 invoked by uid 500); 13 Nov 2015 05:32:18 -0000 Delivered-To: apmail-geode-commits-archive@geode.apache.org Received: (qmail 18717 invoked by uid 500); 13 Nov 2015 05:32:18 -0000 Mailing-List: contact commits-help@geode.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@geode.incubator.apache.org Delivered-To: mailing list commits@geode.incubator.apache.org Received: (qmail 18707 invoked by uid 99); 13 Nov 2015 05:32:18 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Nov 2015 05:32:18 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id BD467C0481 for ; Fri, 13 Nov 2015 05:32:17 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.77 X-Spam-Level: * X-Spam-Status: No, score=1.77 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id COIv4lqQ0zvO for ; Fri, 13 Nov 2015 05:32:05 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 510CE439CD for ; Fri, 13 Nov 2015 05:32:04 +0000 (UTC) Received: (qmail 17246 invoked by uid 99); 13 Nov 2015 05:32:03 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 13 Nov 2015 05:32:03 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id BF14FDFB87; Fri, 13 Nov 2015 05:32:03 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: abaker@apache.org To: commits@geode.incubator.apache.org Date: Fri, 13 Nov 2015 05:32:03 -0000 Message-Id: <47fda3ed50de48fbabee30119721dc30@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/3] incubator-geode git commit: GEODE-544: Removes soplog code and tests Repository: incubator-geode Updated Branches: refs/heads/develop 781bd8d74 -> 9438c8b18 http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplog.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplog.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplog.java deleted file mode 100644 index 8995f66..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplog.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog.nofile; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Collections; -import java.util.EnumMap; -import java.util.NavigableMap; -import java.util.concurrent.ConcurrentSkipListMap; -import java.util.concurrent.atomic.AtomicReference; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.AbstractSortedReader; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedBuffer.BufferIterator; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedOplog; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedOplogFactory.SortedOplogConfiguration; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedReader.Metadata; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedReader.SortedStatistics; - -public class NoFileSortedOplog implements SortedOplog { - private final SortedOplogConfiguration config; - - private final AtomicReference> data; - private final EnumMap metadata; - private final NoFileStatistics stats; - - public NoFileSortedOplog(SortedOplogConfiguration config) { - this.config = config; - - data = new AtomicReference>(); - metadata = new EnumMap(Metadata.class); - stats = new NoFileStatistics(); - } - - @Override - public SortedOplogReader createReader() throws IOException { - return new NoFileReader(); - } - - @Override - public SortedOplogWriter createWriter() throws IOException { - synchronized (metadata) { - metadata.clear(); - } - data.set(new ConcurrentSkipListMap(config.getComparator())); - - return new NoFileWriter(); - } - - private class NoFileWriter implements SortedOplogWriter { - @Override - public void append(byte[] key, byte[] value) throws IOException { - if (data.get().put(key, value) == null) { - stats.add(key.length, value.length); - } - } - - @Override - public void append(ByteBuffer key, ByteBuffer value) throws IOException { - byte[] k = new byte[key.remaining()]; - byte[] v = new byte[value.remaining()]; - - key.get(k); - value.get(v); - - append(k, v); - } - - @Override - public void close(EnumMap meta) throws IOException { - if (meta != null) { - synchronized (metadata) { - metadata.putAll(meta); - } - } - } - - @Override - public void closeAndDelete() throws IOException { - data.get().clear(); - data.set(null); - } - } - - private class NoFileReader extends AbstractSortedReader implements SortedOplogReader { - private final BloomFilter bloom; - private volatile boolean closed; - - public NoFileReader() { - closed = false; - bloom = new BloomFilter() { - @Override - public boolean mightContain(byte[] key) { - return data.get().containsKey(key); - } - }; - } - - @Override - public boolean mightContain(byte[] key) throws IOException { - return bloom.mightContain(key); - } - - @Override - public ByteBuffer read(byte[] key) throws IOException { - return ByteBuffer.wrap(data.get().get(key)); - } - - @Override - public SortedIterator scan( - byte[] from, boolean fromInclusive, - byte[] to, boolean toInclusive, - boolean ascending, - MetadataFilter filter) { - - if (filter == null || filter.accept(metadata.get(filter.getName()))) { - NavigableMap subset = ascending ? data.get() : data.get().descendingMap(); - if (from == null && to == null) { - // we're good - } else if (from == null) { - subset = subset.headMap(to, toInclusive); - } else if (to == null) { - subset = subset.tailMap(from, fromInclusive); - } else { - subset = subset.subMap(from, fromInclusive, to, toInclusive); - } - return new BufferIterator(subset.entrySet().iterator()); - } - return new BufferIterator(Collections.emptyMap().entrySet().iterator()); - } - - @Override - public SerializedComparator getComparator() { - return (SerializedComparator) data.get().comparator(); - } - - @Override - public SortedStatistics getStatistics() { - return stats; - } - - @Override - public boolean isClosed() { - return closed; - } - - @Override - public void close() throws IOException { - closed = true; - } - - @Override - public BloomFilter getBloomFilter() { - return bloom; - } - - @Override - public byte[] getMetadata(Metadata name) { - synchronized (metadata) { - return metadata.get(name); - } - } - - @Override - public File getFile() { - return new File("."); - } - - @Override - public String getFileName() { - return "name"; - } - - @Override - public long getModificationTimeStamp() throws IOException { - return 0; - } - - @Override - public void rename(String name) throws IOException { - } - - @Override - public void delete() throws IOException { - } - } - - private class NoFileStatistics implements SortedStatistics { - private long keys; - private double avgKeySize; - private double avgValueSize; - - private synchronized void add(int keyLength, int valueLength) { - avgKeySize = (keyLength + keys * avgKeySize) / (keys + 1); - avgValueSize = (keyLength + keys * avgValueSize) / (keys + 1); - - keys++; - } - - @Override - public synchronized long keyCount() { - return keys; - } - - @Override - public byte[] firstKey() { - return data.get().firstKey(); - } - - @Override - public byte[] lastKey() { - return data.get().lastKey(); - } - - @Override - public synchronized double avgKeySize() { - return avgKeySize; - } - - @Override - public synchronized double avgValueSize() { - return avgValueSize; - } - - @Override - public void close() { - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplogFactory.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplogFactory.java b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplogFactory.java deleted file mode 100644 index 365d796..0000000 --- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplogFactory.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog.nofile; - -import java.io.File; -import java.io.IOException; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedOplog; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedOplogFactory; - -public class NoFileSortedOplogFactory implements SortedOplogFactory { - private final SortedOplogConfiguration config; - - public NoFileSortedOplogFactory(String name) { - config = new SortedOplogConfiguration(name); - } - - @Override - public SortedOplog createSortedOplog(File name) throws IOException { - return new NoFileSortedOplog(config); - } - - @Override - public SortedOplogConfiguration getConfiguration() { - return config; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/AppendLog.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/AppendLog.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/AppendLog.java deleted file mode 100644 index e0e696a..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/AppendLog.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.io.BufferedOutputStream; -import java.io.Closeable; -import java.io.DataOutputStream; -import java.io.File; -import java.io.FileOutputStream; -import java.io.IOException; - -public class AppendLog { - - public static AppendLogReader recover(File f) throws IOException { - throw new RuntimeException("Not implemented"); - } - - public static AppendLogWriter create(File f) throws IOException { - DataOutputStream dos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(f))); - return new AppendLogWriter(f, dos); - } - - public static class AppendLogReader { - } - - public static class AppendLogWriter implements Closeable { - private final File file; - private final DataOutputStream out; - - private AppendLogWriter(File f, DataOutputStream out) { - this.file = f; - this.out = out; - } - - public synchronized void append(byte[] key, byte[] value) throws IOException { - out.writeInt(key.length); - out.writeInt(value.length); - out.write(key); - out.write(value); - } - - @Override - public void close() throws IOException { - out.close(); - } - - public File getFile() { - return file; - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/ArraySerializedComparatorJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/ArraySerializedComparatorJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/ArraySerializedComparatorJUnitTest.java deleted file mode 100644 index 3689255..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/ArraySerializedComparatorJUnitTest.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.io.IOException; -import java.nio.ByteBuffer; - -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedReader.SerializedComparator; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -@Category(UnitTest.class) -public class ArraySerializedComparatorJUnitTest extends ComparisonTestCase { - protected ArraySerializedComparator comp; - - public void testSearch() throws IOException { - byte[] k1 = comp.createCompositeKey(convert("aaaa"), convert(1), convert(true)); - byte[] k2 = comp.createCompositeKey(convert("bbbb"), convert(2), convert(false)); - byte[] k3 = comp.createCompositeKey(convert("bbbb"), convert(3), convert(true)); - byte[] k4 = comp.createCompositeKey(convert("cccc"), convert(1), convert(false)); - - byte[] s1 = comp.createCompositeKey(convert("aaaa"), - new byte[] {SoplogToken.WILDCARD.toByte()}, new byte[] {SoplogToken.WILDCARD.toByte()}); - - - byte[] s2 = comp.createCompositeKey(convert("bbbb"), - new byte[] {SoplogToken.WILDCARD.toByte()}, new byte[] {SoplogToken.WILDCARD.toByte()}); - - byte[] s3 = comp.createCompositeKey(new byte[] {SoplogToken.WILDCARD.toByte()}, convert(1), - new byte[] {SoplogToken.WILDCARD.toByte()}); - - compareAsIs(comp, k1, s1, Comparison.EQ); - compareAsIs(comp, k2, s1, Comparison.GT); - compareAsIs(comp, k1, s2, Comparison.LT); - compareAsIs(comp, k2, s2, Comparison.EQ); - compareAsIs(comp, k3, s2, Comparison.EQ); - compareAsIs(comp, k4, s2, Comparison.GT); - compareAsIs(comp, s3, k4, Comparison.EQ); - } - - public void testCompositeKey() throws IOException { - byte[] k1 = comp.createCompositeKey(convert("aaaa"), convert(1), convert(true)); - byte[] k2 = comp.createCompositeKey(convert("bbbb"), convert(2), convert(false)); - byte[] k3 = comp.createCompositeKey(convert("bbbb"), convert(3), convert(true)); - byte[] k4 = comp.createCompositeKey(convert("cccc"), convert(1), convert(false)); - byte[] k5 = comp.createCompositeKey(convert(null), convert(1), convert(false)); - byte[] k6 = comp.createCompositeKey(convert(null), convert(1), convert(true)); - - compareAsIs(comp, k1, k1, Comparison.EQ); - compareAsIs(comp, k1, k2, Comparison.LT); - compareAsIs(comp, k2, k1, Comparison.GT); - compareAsIs(comp, k2, k3, Comparison.LT); - compareAsIs(comp, k3, k4, Comparison.LT); - - compareAsIs(comp, k4, k5, Comparison.LT); - compareAsIs(comp, k5, k1, Comparison.GT); - compareAsIs(comp, k5, k6, Comparison.LT); - } - - public void testGetKey() throws Exception { - Object[] vals = new Object[] { "aaaa", 1, true }; - - byte[][] composite = new byte[][] { convert(vals[0]), convert(vals[1]), convert(vals[2]) }; - ByteBuffer key = ByteBuffer.wrap(comp.createCompositeKey(composite)); - - for (int i = 0; i < 3; i++) { - ByteBuffer subkey = comp.getKey(key, i); - assertEquals(vals[i], recover(subkey.array(), subkey.arrayOffset(), subkey.remaining())); - } - } - - public void setUp() { - comp = new ArraySerializedComparator(); - comp.setComparators(new SerializedComparator[] { - new LexicographicalComparator(), // string - new LexicographicalComparator(), // int - new LexicographicalComparator() // boolean - }); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/CompactionSortedOplogSetTestCase.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/CompactionSortedOplogSetTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/CompactionSortedOplogSetTestCase.java deleted file mode 100644 index bca52a9..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/CompactionSortedOplogSetTestCase.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.concurrent.Executors; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.CompactionTestCase.FileTracker; -import com.gemstone.gemfire.internal.cache.persistence.soplog.CompactionTestCase.WaitingHandler; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedReader.SortedIterator; -import com.gemstone.gemfire.internal.cache.persistence.soplog.nofile.NoFileSortedOplogFactory; - -public abstract class CompactionSortedOplogSetTestCase extends SortedOplogSetJUnitTest { - public void testWithCompaction() throws IOException, InterruptedException { - FlushCounter handler = new FlushCounter(); - SortedOplogSet sos = createSoplogSet("compact"); - - for (int i = 0; i < 1000; i++) { - sos.put(wrapInt(i), wrapInt(i)); - if (i % 100 == 0) { - sos.flush(null, handler); - } - } - - flushAndWait(handler, sos); - - compactAndWait(sos, false); - validate(sos, 1000); - sos.close(); - } - - public void testTombstone() throws Exception { - FlushCounter handler = new FlushCounter(); - SortedOplogFactory factory = new NoFileSortedOplogFactory("tombstone"); - Compactor compactor = new SizeTieredCompactor(factory, - NonCompactor.createFileset("tombstone", new File(".")), - new FileTracker(), - Executors.newSingleThreadExecutor(), - 2, 2); - - SortedOplogSet sos = new SortedOplogSetImpl(factory, Executors.newSingleThreadExecutor(), compactor); - - for (int i = 0; i < 1000; i++) { - sos.put(wrapInt(i), wrapInt(i)); - } - sos.flush(null, handler); - - for (int i = 900; i < 1000; i++) { - sos.put(wrapInt(i), new byte[] {SoplogToken.TOMBSTONE.toByte()}); - } - flushAndWait(handler, sos); - compactAndWait(sos, true); - - validate(sos, 900); - sos.close(); - - } - - public void testInUse() throws Exception { - FlushCounter handler = new FlushCounter(); - SortedOplogSet sos = createSoplogSet("inuse"); - - for (int i = 0; i < 1000; i++) { - sos.put(wrapInt(i), wrapInt(i)); - } - - flushAndWait(handler, sos); - - // start iterating over soplog - SortedIterator range = sos.scan(); - assertEquals(0, ((SizeTieredCompactor) sos.getCompactor()).countInactiveReaders()); - - for (int i = 1000; i < 5000; i++) { - sos.put(wrapInt(i), wrapInt(i)); - if (i % 100 == 0) { - sos.flush(null, handler); - } - } - - flushAndWait(handler, sos); - compactAndWait(sos, false); - assertEquals(1, ((SizeTieredCompactor) sos.getCompactor()).countInactiveReaders()); - - range.close(); - compactAndWait(sos, false); - assertEquals(0, ((SizeTieredCompactor) sos.getCompactor()).countInactiveReaders()); - - validate(sos, 5000); - sos.close(); - } - - @Override - protected SortedOplogSetImpl createSoplogSet(String name) throws IOException { - SortedOplogFactory factory = new NoFileSortedOplogFactory(name); - Compactor compactor = createCompactor(factory); - - return new SortedOplogSetImpl(factory, Executors.newSingleThreadExecutor(), compactor); - } - - protected abstract AbstractCompactor createCompactor(SortedOplogFactory factory) throws IOException; - - private void validate(SortedReader range, int count) throws IOException { - int i = 0; - for (SortedIterator iter = range.scan(); iter.hasNext(); i++) { - iter.next(); - assertEquals(i, iter.key().getInt()); - } - assertEquals(count, i); - range.close(); - } - - private void compactAndWait(SortedOplogSet sos, boolean force) throws InterruptedException { - WaitingHandler wh = new WaitingHandler(); - sos.getCompactor().compact(force, wh); - wh.waitForCompletion(); - assertNull(wh.getError()); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/CompactionTestCase.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/CompactionTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/CompactionTestCase.java deleted file mode 100644 index 7577b53..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/CompactionTestCase.java +++ /dev/null @@ -1,206 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.io.File; -import java.io.IOException; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicReference; - -import org.apache.logging.log4j.Logger; - -import junit.framework.TestCase; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.Compactor.CompactionHandler; -import com.gemstone.gemfire.internal.cache.persistence.soplog.Compactor.CompactionTracker; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedOplog.SortedOplogWriter; -import com.gemstone.gemfire.internal.cache.persistence.soplog.nofile.NoFileSortedOplogFactory; -import com.gemstone.gemfire.internal.logging.LogService; - -public abstract class CompactionTestCase> extends TestCase { - private static final Logger logger = LogService.getLogger(); - protected SortedOplogFactory factory; - protected AbstractCompactor compactor; - - public void testMaxCompaction() throws Exception { - for (int i = 0; i < 100; i += 2) { - compactor.add(createSoplog(0, 100, i)); - compactor.add(createSoplog(100, 100, i+1)); - - WaitingHandler wh = new WaitingHandler(); - compactor.compact(false, wh); - wh.waitForCompletion(); - } - - WaitingHandler wh = new WaitingHandler(); - compactor.compact(true, wh); - wh.waitForCompletion(); - } - - public void testClear() throws IOException { - compactor.add(createSoplog(0, 100, 0)); - compactor.add(createSoplog(100, 100, 1)); - compactor.clear(); - - assertEquals(0, compactor.getActiveReaders(null, null).size()); - assertFalse(compactor.getLevel(0).needsCompaction()); - } - - public void testInterruptedCompaction() throws IOException { - compactor.add(createSoplog(0, 100, 0)); - compactor.add(createSoplog(100, 100, 1)); - - compactor.testAbortDuringCompaction = true; - boolean compacted = compactor.compact(); - - assertFalse(compacted); - assertEquals(2, compactor.getActiveReaders(null, null).size()); - assertTrue(compactor.getLevel(0).needsCompaction()); - } - - public void testClearDuringCompaction() throws Exception { - compactor.add(createSoplog(0, 100, 0)); - compactor.add(createSoplog(100, 100, 1)); - - compactor.testDelayDuringCompaction = new CountDownLatch(1); - WaitingHandler wh = new WaitingHandler(); - - logger.debug("Invoking compact"); - compactor.compact(false, wh); - - logger.debug("Invoking clear"); - compactor.clear(); - - boolean compacted = wh.waitForCompletion(); - - assertFalse(compacted); - assertEquals(0, compactor.getActiveReaders(null, null).size()); - } - - public void testClearRepeat() throws Exception { - int i = 0; - do { - testClearDuringCompaction(); - logger.debug("Test {} is complete", i); - tearDown(); - setUp(); - } while (i++ < 100); - } - - public void testCloseRepeat() throws Exception { - int i = 0; - do { - testCloseDuringCompaction(); - logger.debug("Test {} is complete", i); - tearDown(); - setUp(); - } while (i++ < 100); - } - - public void testCloseDuringCompaction() throws Exception { - compactor.add(createSoplog(0, 100, 0)); - compactor.add(createSoplog(100, 100, 1)); - - compactor.testDelayDuringCompaction = new CountDownLatch(1); - WaitingHandler wh = new WaitingHandler(); - - compactor.compact(false, wh); - compactor.close(); - - boolean compacted = wh.waitForCompletion(); - - assertFalse(compacted); - assertEquals(0, compactor.getActiveReaders(null, null).size()); - } - - public void setUp() throws IOException { - factory = new NoFileSortedOplogFactory("test"); - compactor = createCompactor(factory); - } - - public void tearDown() throws Exception { - compactor.close(); - for (File f : SortedReaderTestCase.getSoplogsToDelete()) { - f.delete(); - } - } - - protected SortedOplog createSoplog(int start, int count, int id) throws IOException { - SortedOplog soplog = factory.createSortedOplog(new File("test-" + id + ".soplog")); - SortedOplogWriter wtr = soplog.createWriter(); - try { - for (int i = start; i < start + count; i++) { - wtr.append(SortedReaderTestCase.wrapInt(i), SortedReaderTestCase.wrapInt(i)); - } - } finally { - wtr.close(null); - } - return soplog; - } - - protected abstract AbstractCompactor createCompactor(SortedOplogFactory factory) throws IOException; - - static class WaitingHandler implements CompactionHandler { - private final CountDownLatch latch; - private final AtomicReference err; - private volatile boolean compacted; - - public WaitingHandler() { - latch = new CountDownLatch(1); - err = new AtomicReference(); - } - - public boolean waitForCompletion() throws InterruptedException { - logger.debug("Waiting for compaction to complete"); - latch.await(); - logger.debug("Done waiting!"); - - return compacted; - } - - public Throwable getError() { - return err.get(); - } - - @Override - public void complete(boolean compacted) { - logger.debug("Compaction completed with {}", compacted); - this.compacted = compacted; - latch.countDown(); - } - - @Override - public void failed(Throwable ex) { - err.set(ex); - latch.countDown(); - } - } - - static class FileTracker implements CompactionTracker { - @Override - public void fileDeleted(File f) { - } - - @Override - public void fileAdded(File f, Integer attach) { - } - - @Override - public void fileRemoved(File f, Integer attach) { - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/ComparisonTestCase.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/ComparisonTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/ComparisonTestCase.java deleted file mode 100644 index cb9e909..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/ComparisonTestCase.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; - -import junit.framework.TestCase; - -import com.gemstone.gemfire.DataSerializer; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedReader.SerializedComparator; - -public abstract class ComparisonTestCase extends TestCase { - public enum Comparison { - EQ(0.0), - LT(-1.0), - GT(1.0); - - private final double sgn; - - private Comparison(double sgn) { - this.sgn = sgn; - } - - public double signum() { - return sgn; - } - - public Comparison opposite() { - switch (this) { - case LT: return GT; - case GT : return LT; - default : return EQ; - } - } - } - - public void compare(SerializedComparator sc, Object o1, Object o2, Comparison result) throws IOException { - double diff = sc.compare(convert(o1), convert(o2)); - assertEquals(String.format("%s ? %s", o1, o2), result.signum(), Math.signum(diff)); - } - - public void compareAsIs(SerializedComparator sc, byte[] b1, byte[] b2, Comparison result) throws IOException { - double diff = sc.compare(b1, b2); - assertEquals(result.signum(), Math.signum(diff)); - } - - public static byte[] convert(Object o) throws IOException { - ByteArrayOutputStream b = new ByteArrayOutputStream(); - DataOutputStream d = new DataOutputStream(b); - DataSerializer.writeObject(o, d); - - return b.toByteArray(); - } - - public static Object recover(byte[] obj, int off, int len) throws ClassNotFoundException, IOException { - DataInputStream in = new DataInputStream(new ByteArrayInputStream(obj, off, len)); - return DataSerializer.readObject(in); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/IndexComparatorJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/IndexComparatorJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/IndexComparatorJUnitTest.java deleted file mode 100644 index 27202ec..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/IndexComparatorJUnitTest.java +++ /dev/null @@ -1,79 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.io.IOException; -import java.nio.ByteBuffer; - -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -@Category(UnitTest.class) -public class IndexComparatorJUnitTest extends ComparisonTestCase { - protected IndexSerializedComparator comp; - - public void testSearch() throws IOException { - byte[] k1 = comp.createCompositeKey(convert("aaaa"), convert(1)); - byte[] k2 = comp.createCompositeKey(convert("bbbb"), convert(2)); - byte[] k3 = comp.createCompositeKey(convert("bbbb"), convert(3)); - byte[] k4 = comp.createCompositeKey(convert(null), convert(1)); - - byte[] s1 = comp.createCompositeKey(convert("aaaa"), new byte[] {SoplogToken.WILDCARD.toByte()}); - byte[] s2 = comp.createCompositeKey(convert("bbbb"), new byte[] {SoplogToken.WILDCARD.toByte()}); - byte[] s3 = comp.createCompositeKey(new byte[] {SoplogToken.WILDCARD.toByte()}, convert(1)); - - compareAsIs(comp, k1, s1, Comparison.EQ); - compareAsIs(comp, k2, s1, Comparison.GT); - compareAsIs(comp, k1, s2, Comparison.LT); - compareAsIs(comp, k2, s2, Comparison.EQ); - compareAsIs(comp, k3, s2, Comparison.EQ); - compareAsIs(comp, k4, s2, Comparison.GT); - compareAsIs(comp, s3, k4, Comparison.EQ); - } - - public void testCompositeKey() throws IOException { - byte[] k1 = comp.createCompositeKey(convert("aaaa"), convert(1)); - byte[] k2 = comp.createCompositeKey(convert("bbbb"), convert(2)); - byte[] k3 = comp.createCompositeKey(convert("bbbb"), convert(3)); - byte[] k4 = comp.createCompositeKey(convert("cccc"), convert(1)); - byte[] k5 = comp.createCompositeKey(convert(null), convert(1)); - - compareAsIs(comp, k1, k1, Comparison.EQ); - compareAsIs(comp, k1, k2, Comparison.LT); - compareAsIs(comp, k2, k1, Comparison.GT); - compareAsIs(comp, k2, k3, Comparison.LT); - compareAsIs(comp, k3, k4, Comparison.LT); - - compareAsIs(comp, k4, k5, Comparison.LT); - compareAsIs(comp, k5, k1, Comparison.GT); - } - - public void testGetKey() throws Exception { - ByteBuffer key = ByteBuffer.wrap(comp.createCompositeKey(convert("aaaa"), convert(1))); - - ByteBuffer k1 = comp.getKey(key, 0); - assertEquals("aaaa", recover(k1.array(), k1.arrayOffset(), k1.remaining())); - - ByteBuffer k2 = comp.getKey(key, 1); - assertEquals(1, recover(k2.array(), k2.arrayOffset(), k2.remaining())); - } - - public void setUp() { - comp = new IndexSerializedComparator(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/LexicographicalComparatorJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/LexicographicalComparatorJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/LexicographicalComparatorJUnitTest.java deleted file mode 100644 index 0c0e93e..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/LexicographicalComparatorJUnitTest.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.math.BigInteger; -import java.nio.ByteBuffer; - -import org.apache.hadoop.hbase.util.Bytes; -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.internal.DSCODE; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -@Category(UnitTest.class) -public class LexicographicalComparatorJUnitTest extends ComparisonTestCase { - private LexicographicalComparator lc; - - public void testMixedNumeric() throws Exception { - compare(lc, (byte) 1, (short) 2, Comparison.LT); - compare(lc, (byte) 1, (int) 2, Comparison.LT); - compare(lc, (byte) 1, (long) 2, Comparison.LT); - compare(lc, (byte) 1, 2.1f, Comparison.LT); - compare(lc, (byte) 1, 2.1d, Comparison.LT); - - compare(lc, (short) 1, (byte) 2, Comparison.LT); - compare(lc, (short) 1, (int) 2, Comparison.LT); - compare(lc, (short) 1, (long) 2, Comparison.LT); - compare(lc, (short) 1, 2.1f, Comparison.LT); - compare(lc, (short) 1, 2.1d, Comparison.LT); - - compare(lc, (int) 1, (byte) 2, Comparison.LT); - compare(lc, (int) 1, (short) 2, Comparison.LT); - compare(lc, (int) 1, (long) 2, Comparison.LT); - compare(lc, (int) 1, 2.1f, Comparison.LT); - compare(lc, (int) 1, 2.1d, Comparison.LT); - - compare(lc, (long) 1, (byte) 2, Comparison.LT); - compare(lc, (long) 1, (short) 2, Comparison.LT); - compare(lc, (long) 1, (int) 2, Comparison.LT); - compare(lc, (long) 1, 2.1f, Comparison.LT); - compare(lc, (long) 1, 2.1d, Comparison.LT); - - compare(lc, 1.1f, (byte) 2, Comparison.LT); - compare(lc, 1.1f, (short) 2, Comparison.LT); - compare(lc, 1.1f, (int) 2, Comparison.LT); - compare(lc, 1.1f, (long) 2, Comparison.LT); - compare(lc, 1.1f, 2.1d, Comparison.LT); - - compare(lc, 1.1d, (byte) 2, Comparison.LT); - compare(lc, 1.1d, (short) 2, Comparison.LT); - compare(lc, 1.1d, (int) 2, Comparison.LT); - compare(lc, 1.1d, (long) 2, Comparison.LT); - compare(lc, 1.1d, 2.1f, Comparison.LT); - } - - public void testBoolean() throws Exception { - compare(lc, Boolean.TRUE, Boolean.TRUE, Comparison.EQ); - compare(lc, Boolean.FALSE, Boolean.FALSE, Comparison.EQ); - compare(lc, Boolean.TRUE, Boolean.FALSE, Comparison.GT); - compare(lc, Boolean.FALSE, Boolean.TRUE, Comparison.LT); - } - - public void testByte() throws Exception { - compare(lc, (byte) 0, (byte) 0, Comparison.EQ); - compare(lc, (byte) 0, (byte) 1, Comparison.LT); - compare(lc, (byte) -1, (byte) 1, Comparison.LT); - compare(lc, (byte) 1, (byte) -1, Comparison.GT); - compare(lc, (byte) -2, (byte) -1, Comparison.LT); - compare(lc, (byte) 1, (byte) 2, Comparison.LT); - compare(lc, (byte) 2, (byte) 1, Comparison.GT); - } - - public void testShort() throws Exception { - compare(lc, (short) 0, (short) 0, Comparison.EQ); - compare(lc, (short) 0, (short) 1, Comparison.LT); - compare(lc, (short) -1, (short) 1, Comparison.LT); - compare(lc, (short) 1, (short) -1, Comparison.GT); - compare(lc, (short) -2, (short) -1, Comparison.LT); - compare(lc, (short) 1, (short) 2, Comparison.LT); - compare(lc, (short) 2, (short) 1, Comparison.GT); - } - - public void testInt() throws Exception { - compare(lc, (int) 0, (int) 0, Comparison.EQ); - compare(lc, (int) 0, (int) 1, Comparison.LT); - compare(lc, (int) -1, (int) 1, Comparison.LT); - compare(lc, (int) 1, (int) -1, Comparison.GT); - compare(lc, (int) -2, (int) -1, Comparison.LT); - compare(lc, (int) 1, (int) 2, Comparison.LT); - compare(lc, (int) 2, (int) 1, Comparison.GT); - } - - public void testLong() throws Exception { - compare(lc, (long) 0, (long) 0, Comparison.EQ); - compare(lc, (long) 0, (long) 1, Comparison.LT); - compare(lc, (long) -1, (long) 1, Comparison.LT); - compare(lc, (long) 1, (long) -1, Comparison.GT); - compare(lc, (long) -2, (long) -1, Comparison.LT); - compare(lc, (long) 1, (long) 2, Comparison.LT); - compare(lc, (long) 2, (long) 1, Comparison.GT); - } - - public void testFloat() throws Exception { - compare(lc, 0.0f, 0.0f, Comparison.EQ); - compare(lc, 0.0f, 1.0f, Comparison.LT); - compare(lc, -1.0f, 1.0f, Comparison.LT); - compare(lc, 1.0f, -1.0f, Comparison.GT); - compare(lc, -2.0f, -1.0f, Comparison.LT); - compare(lc, 1.0f, 2.0f, Comparison.LT); - compare(lc, 2.0f, 1.0f, Comparison.GT); - compare(lc, 2.1f, 0.9f, Comparison.GT); - } - - public void testDouble() throws Exception { - compare(lc, 0.0d, 0.0d, Comparison.EQ); - compare(lc, 0.0d, 1.0d, Comparison.LT); - compare(lc, -1.0d, 1.0d, Comparison.LT); - compare(lc, 1.0d, -1.0d, Comparison.GT); - compare(lc, -2.0d, -1.0d, Comparison.LT); - compare(lc, 1.0d, 2.0d, Comparison.LT); - compare(lc, 2.0d, 1.0d, Comparison.GT); - compare(lc, 2.1d, 0.9d, Comparison.GT); - } - - public void testString() throws Exception { - compare(lc, "", "", Comparison.EQ); - compare(lc, "aa", "a", Comparison.GT); - compare(lc, "a", "b", Comparison.LT); - compare(lc, "b", "a", Comparison.GT); - compare(lc, "baah", "aardvark", Comparison.GT); - compare(lc, "Chloé", "Réal", Comparison.LT); - compare(lc, "chowder", "Réal", Comparison.GT); - compare(lc, "Réal", "chowder", Comparison.LT); - compare(lc, "Réal", "Réa", Comparison.GT); - compare(lc, "Réal", "Réa", Comparison.GT); - compare(lc, "\u0061\u00a2\u0f00", "\u0061\u00a2\u0f00\u0061", Comparison.LT); - } - - public void testChar() throws Exception { - compare(lc, 'a', 'a', Comparison.EQ); - compare(lc, 'a', 'b', Comparison.LT); - compare(lc, 'b', 'a', Comparison.GT); - } - - public void testNull() throws Exception { - compare(lc, null, null, Comparison.EQ); - compare(lc, null, "hi mom", Comparison.GT); - compare(lc, "hi mom", null, Comparison.LT); - } - - public void testObject() throws Exception { - compare(lc, new BigInteger("1"), new BigInteger("1"), Comparison.EQ); - compare(lc, new BigInteger("1"), new BigInteger("0"), Comparison.GT); - compare(lc, new BigInteger("-1"), new BigInteger("0"), Comparison.LT); - } - - public void testIntPerformance() throws Exception { - ByteBuffer b1 = ByteBuffer.allocate(5).put(0, DSCODE.INTEGER); - ByteBuffer b2 = ByteBuffer.allocate(5).put(0, DSCODE.INTEGER); - - for (int n = 0; n < 5; n++) { - long diff = 0; - int count = 10000000; - long start = System.nanoTime(); - for (int i = 0; i < count; i++) { - b1.putInt(1, i); - b2.putInt(1, i + 1); - diff += lc.compare(b1.array(), b1.arrayOffset(), b1.capacity(), b2.array(), b2.arrayOffset(), b2.capacity()); - } - long nanos = System.nanoTime() - start; - - System.out.printf("(%d) %f int comparisons / ms\n", diff, 1000000.0 * count / nanos); - - diff = 0; - start = System.nanoTime(); - for (int i = 0; i < count; i++) { - b1.putInt(1, i); - b2.putInt(1, i + 1); - diff += Bytes.compareTo(b1.array(), b1.arrayOffset(), b1.capacity(), b2.array(), b2.arrayOffset(), b2.capacity()); - } - nanos = System.nanoTime() - start; - - System.out.printf("(%d) %f byte comparisons / ms\n\n", diff, 1000000.0 * count / nanos); - } - } - - protected void setUp() { - lc = new LexicographicalComparator(); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/RecoverableSortedOplogSet.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/RecoverableSortedOplogSet.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/RecoverableSortedOplogSet.java deleted file mode 100644 index 0b3e1f5..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/RecoverableSortedOplogSet.java +++ /dev/null @@ -1,221 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.io.File; -import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.nio.ByteBuffer; -import java.util.EnumMap; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicReference; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -import org.apache.logging.log4j.Logger; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.AppendLog.AppendLogWriter; -import com.gemstone.gemfire.internal.logging.LogService; - -public class RecoverableSortedOplogSet extends AbstractSortedReader implements SortedOplogSet { - private static final Logger logger = LogService.getLogger(); - - private final SortedOplogSet sos; - private final long bufferSize; - - private final long maxBufferMemory; - - private final Lock rollLock; - private AtomicReference writer; - - private final String logPrefix; - - public RecoverableSortedOplogSet(SortedOplogSet sos, long bufferSize, double memLimit) throws IOException { - this.sos = sos; - this.bufferSize = bufferSize; - - this.logPrefix = "<" + sos.getFactory().getConfiguration().getName() + "> "; - - rollLock = new ReentrantLock(); - writer = new AtomicReference(AppendLog.create(nextLogFile())); - - maxBufferMemory = Math.round(memLimit * ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getMax()); - } - - @Override - public boolean mightContain(byte[] key) throws IOException { - return sos.mightContain(key); - } - - @Override - public ByteBuffer read(byte[] key) throws IOException { - return sos.read(key); - } - - @Override - public SortedIterator scan(byte[] from, boolean fromInclusive, byte[] to, boolean toInclusive) throws IOException { - return sos.scan(from, fromInclusive, to, toInclusive); - } - - @Override - public SortedIterator scan( - byte[] from, - boolean fromInclusive, - byte[] to, - boolean toInclusive, - boolean ascending, - MetadataFilter filter) throws IOException { - return sos.scan(from, fromInclusive, to, toInclusive, ascending, filter); - } - - @Override - public SerializedComparator getComparator() { - return sos.getComparator(); - } - - @Override - public SortedOplogFactory getFactory() { - return sos.getFactory(); - } - - @Override - public SortedStatistics getStatistics() throws IOException { - return sos.getStatistics(); - } - - @Override - public void close() throws IOException { - rollLock.lock(); - try { - writer.get().close(); - writer.set(null); - sos.close(); - } finally { - rollLock.unlock(); - } - } - - @Override - public void put(byte[] key, byte[] value) throws IOException { - throttle(); - if (sos.bufferSize() > bufferSize) { - roll(false); - } - - writer.get().append(key, value); - sos.put(key, value); - } - - @Override - public long bufferSize() { - return sos.bufferSize(); - } - - @Override - public long unflushedSize() { - return sos.unflushedSize(); - } - - @Override - public void flush(EnumMap metadata, FlushHandler handler) throws IOException { - roll(true); - } - - @Override - public void flushAndClose(EnumMap metadata) throws IOException { - throw new RuntimeException("Not implemented"); - } - - @Override - public Compactor getCompactor() { - return sos.getCompactor(); - } - - @Override - public void clear() throws IOException { - rollLock.lock(); - try { - roll(true); - sos.clear(); - } finally { - rollLock.unlock(); - } - } - - @Override - public void destroy() throws IOException { - roll(true); - sos.destroy(); - } - - @Override - public boolean isClosed() { - return sos.isClosed(); - } - - private void throttle() { - int n = 0; - while (sos.bufferSize() + sos.unflushedSize() > maxBufferMemory) { - try { - Thread.sleep(1 << n++); - - } catch (InterruptedException e) { - Thread.currentThread().interrupt(); - break; - } - } - } - - private void roll(boolean wait) throws IOException { - boolean locked = true; - if (wait) { - rollLock.lock(); - } else { - locked = rollLock.tryLock(); - } - - if (locked) { - try { - AppendLogWriter next = AppendLog.create(nextLogFile()); - final AppendLogWriter old = writer.getAndSet(next); - old.close(); - - if (logger.isDebugEnabled()) { - logger.debug("{}Rolling from {} to {}", this.logPrefix, old.getFile(), next.getFile()); - } - - sos.flush(null, new FlushHandler() { - @Override - public void complete() { - old.getFile().delete(); - } - - @Override - public void error(Throwable t) { - } - }); - } finally { - rollLock.unlock(); - } - } - } - - private File nextLogFile() { - return new File(sos.getFactory().getConfiguration().getName() - + "-" + UUID.randomUUID().toString() + ".aolog"); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SizeTieredCompactorJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SizeTieredCompactorJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SizeTieredCompactorJUnitTest.java deleted file mode 100644 index ee76c55..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SizeTieredCompactorJUnitTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.concurrent.Executors; - -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedOplog.SortedOplogReader; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedReader.SortedIterator; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -@Category(UnitTest.class) -public class SizeTieredCompactorJUnitTest extends CompactionTestCase { - public void testBasic() throws Exception { - compactor.add(createSoplog(0, 100, 0)); - - assertEquals(1, compactor.getActiveReaders(null, null).size()); - assertEquals(1, compactor.getLevel(0).getSnapshot().size()); - assertFalse(compactor.getLevel(0).needsCompaction()); - - WaitingHandler wh = new WaitingHandler(); - compactor.compact(false, wh); - wh.waitForCompletion(); - - assertEquals(1, compactor.getActiveReaders(null, null).size()); - assertEquals(1, compactor.getLevel(0).getSnapshot().size()); - assertFalse(compactor.getLevel(0).needsCompaction()); - } - - public void testCompactionLevel0() throws Exception { - compactor.add(createSoplog(0, 100, 0)); - compactor.add(createSoplog(100, 100, 1)); - - assertEquals(2, compactor.getActiveReaders(null, null).size()); - assertEquals(2, compactor.getLevel(0).getSnapshot().size()); - assertTrue(compactor.getLevel(0).needsCompaction()); - - WaitingHandler wh = new WaitingHandler(); - compactor.compact(false, wh); - wh.waitForCompletion(); - - assertEquals(1, compactor.getActiveReaders(null, null).size()); - assertEquals(0, compactor.getLevel(0).getSnapshot().size()); - assertEquals(1, compactor.getLevel(1).getSnapshot().size()); - assertFalse(compactor.getLevel(0).needsCompaction()); - assertFalse(compactor.getLevel(1).needsCompaction()); - - validate(compactor.getActiveReaders(null, null).iterator().next().get(), 0, 200); - } - - public void testMultilevelCompaction() throws Exception { - for (int i = 0; i < 8; i += 2) { - compactor.add(createSoplog(0, 100, i)); - compactor.add(createSoplog(100, 100, i+1)); - - WaitingHandler wh = new WaitingHandler(); - compactor.compact(false, wh); - wh.waitForCompletion(); - } - - assertEquals(1, compactor.getActiveReaders(null, null).size()); - validate(compactor.getActiveReaders(null, null).iterator().next().get(), 0, 200); - } - - public void testForceCompaction() throws Exception { - compactor.add(createSoplog(0, 100, 0)); - compactor.add(createSoplog(100, 100, 1)); - boolean compacted = compactor.compact(); - - assertTrue(compacted); - validate(compactor.getActiveReaders(null, null).iterator().next().get(), 0, 200); - } - - @Override - protected AbstractCompactor createCompactor(SortedOplogFactory factory) throws IOException { - return new SizeTieredCompactor(factory, - NonCompactor.createFileset("test", new File(".")), - new FileTracker(), - Executors.newSingleThreadExecutor(), - 2, 4); - } - - private void validate(SortedOplogReader soplog, int start, int count) throws IOException { - int i = 0; - for (SortedIterator iter = soplog.scan(); iter.hasNext(); i++) { - iter.next(); - assertEquals(i, iter.key().getInt()); - assertEquals(i, iter.value().getInt()); - } - assertEquals(count, i); - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SizeTieredSortedOplogSetJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SizeTieredSortedOplogSetJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SizeTieredSortedOplogSetJUnitTest.java deleted file mode 100644 index cf1de00..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SizeTieredSortedOplogSetJUnitTest.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.io.File; -import java.io.IOException; -import java.util.concurrent.Executors; - -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.CompactionTestCase.FileTracker; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -@Category(UnitTest.class) -public class SizeTieredSortedOplogSetJUnitTest extends CompactionSortedOplogSetTestCase { - @Override - protected AbstractCompactor createCompactor(SortedOplogFactory factory) throws IOException { - return new SizeTieredCompactor(factory, - NonCompactor.createFileset("test", new File(".")), - new FileTracker(), - Executors.newSingleThreadExecutor(), - 2, 4); - } - @Override - public void testStatistics() throws IOException { - // remove this noop override when bug 52249 is fixed - } - -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedBufferJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedBufferJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedBufferJUnitTest.java deleted file mode 100644 index 1d79059..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedBufferJUnitTest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.nio.ByteBuffer; -import java.util.Map.Entry; -import java.util.NavigableMap; - -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedOplogFactory.SortedOplogConfiguration; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -@Category(UnitTest.class) -public class SortedBufferJUnitTest extends SortedReaderTestCase { - @Override - protected SortedReader createReader(NavigableMap data) { - SortedOplogConfiguration config = new SortedOplogConfiguration("test"); - SortedBuffer sb = new SortedBuffer(config, 0); - for (Entry entry : data.entrySet()) { - sb.put(entry.getKey(), entry.getValue()); - } - return sb; - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedOplogSetJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedOplogSetJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedOplogSetJUnitTest.java deleted file mode 100644 index bb0a198..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedOplogSetJUnitTest.java +++ /dev/null @@ -1,273 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.io.File; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.List; -import java.util.Map.Entry; -import java.util.NavigableMap; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executors; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - -import org.apache.logging.log4j.Logger; -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedOplogSet.FlushHandler; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedReader.SortedIterator; -import com.gemstone.gemfire.internal.cache.persistence.soplog.nofile.NoFileSortedOplogFactory; -import com.gemstone.gemfire.internal.logging.LogService; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -@Category(UnitTest.class) -public class SortedOplogSetJUnitTest extends SortedReaderTestCase { - private static final Logger logger = LogService.getLogger(); - private SortedOplogSet set; - - public void testMergedIterator() throws IOException { - FlushCounter handler = new FlushCounter(); - SortedOplogSet sos = createSoplogSet("merge"); - - // #1 - sos.put(wrapInt(1), wrapInt(1)); - sos.put(wrapInt(2), wrapInt(1)); - sos.put(wrapInt(3), wrapInt(1)); - sos.put(wrapInt(4), wrapInt(1)); - sos.flush(null, handler); - - // #2 - sos.put(wrapInt(2), wrapInt(1)); - sos.put(wrapInt(4), wrapInt(1)); - sos.put(wrapInt(6), wrapInt(1)); - sos.put(wrapInt(8), wrapInt(1)); - sos.flush(null, handler); - - // #3 - sos.put(wrapInt(1), wrapInt(1)); - sos.put(wrapInt(3), wrapInt(1)); - sos.put(wrapInt(5), wrapInt(1)); - sos.put(wrapInt(7), wrapInt(1)); - sos.put(wrapInt(9), wrapInt(1)); - sos.flush(null, handler); - - // #4 - sos.put(wrapInt(0), wrapInt(1)); - sos.put(wrapInt(1), wrapInt(1)); - sos.put(wrapInt(4), wrapInt(1)); - sos.put(wrapInt(5), wrapInt(1)); - - while (!handler.flushes.compareAndSet(3, 0)); - - // the iteration pattern for this test should be 0-9: - // 0 1 4 5 sbuffer #4 - // 1 3 5 7 9 soplog #3 - // 2 4 6 8 soplog #2 - // 1 2 3 4 soplog #1 - List result = new ArrayList(); - SortedIterator iter = sos.scan(); - try { - while (iter.hasNext()) { - ByteBuffer key = iter.next(); - ByteBuffer val = iter.value(); - assertEquals(wrapInt(1), val); - - result.add(key.getInt()); - } - } finally { - iter.close(); - } - - sos.close(); - - assertEquals(10, result.size()); - for (int i = 0; i < 10; i++) { - assertEquals(i, result.get(i).intValue()); - } - } - - @Override - protected SortedReader createReader(NavigableMap data) - throws IOException { - set = createSoplogSet("test"); - - int i = 0; - int flushes = 0; - FlushCounter fc = new FlushCounter(); - - for (Entry entry : data.entrySet()) { - set.put(entry.getKey(), entry.getValue()); - if (i++ % 13 == 0) { - flushes++; - set.flush(null, fc); - } - } - - while (!fc.flushes.compareAndSet(flushes, 0)); - return set; - } - - public void testClear() throws IOException { - set.clear(); - validateEmpty(set); - } - - public void testDestroy() throws IOException { - set.destroy(); - assertTrue(((SortedOplogSetImpl) set).isClosed()); - try { - set.scan(); - fail(); - } catch (IllegalStateException e) { } - } - - public void testClearInterruptsFlush() throws Exception { - FlushCounter handler = new FlushCounter(); - SortedOplogSetImpl sos = prepSoplogSet("clearDuringFlush"); - - sos.testDelayDuringFlush = new CountDownLatch(1); - sos.flush(null, handler); - sos.clear(); - - flushAndWait(handler, sos); - validateEmpty(sos); - assertEquals(2, handler.flushes.get()); - } - - public void testClearRepeat() throws Exception { - int i = 0; - do { - testClearInterruptsFlush(); - logger.debug("Test {} is complete", i); - tearDown(); - setUp(); - } while (i++ < 100); - } - - public void testCloseInterruptsFlush() throws Exception { - FlushCounter handler = new FlushCounter(); - SortedOplogSetImpl sos = prepSoplogSet("closeDuringFlush"); - - sos.testDelayDuringFlush = new CountDownLatch(1); - sos.flush(null, handler); - sos.close(); - - assertTrue(sos.isClosed()); - assertEquals(1, handler.flushes.get()); - } - - public void testDestroyInterruptsFlush() throws Exception { - FlushCounter handler = new FlushCounter(); - SortedOplogSetImpl sos = prepSoplogSet("destroyDuringFlush"); - - sos.testDelayDuringFlush = new CountDownLatch(1); - sos.flush(null, handler); - sos.destroy(); - - assertTrue(sos.isClosed()); - assertEquals(1, handler.flushes.get()); - } - - public void testScanAfterClear() throws IOException { - SortedIterator iter = set.scan(); - set.clear(); - assertFalse(iter.hasNext()); - } - - public void testScanAfterClose() throws IOException { - SortedIterator iter = set.scan(); - set.close(); - assertFalse(iter.hasNext()); - } - - public void testEmptyFlush() throws Exception { - FlushCounter handler = new FlushCounter(); - SortedOplogSet sos = prepSoplogSet("empty"); - - flushAndWait(handler, sos); - flushAndWait(handler, sos); - } - - public void testErrorDuringFlush() throws Exception { - FlushCounter handler = new FlushCounter(); - handler.error.set(true); - - SortedOplogSetImpl sos = prepSoplogSet("err"); - sos.testErrorDuringFlush = true; - - flushAndWait(handler, sos); - } - - protected void validateEmpty(SortedOplogSet sos) throws IOException { - assertEquals(0, sos.bufferSize()); - assertEquals(0, sos.unflushedSize()); - - SortedIterator iter = sos.scan(); - assertFalse(iter.hasNext()); - iter.close(); - sos.close(); - } - - protected SortedOplogSetImpl prepSoplogSet(String name) throws IOException { - SortedOplogSetImpl sos = createSoplogSet(name); - - sos.put(wrapInt(1), wrapInt(1)); - sos.put(wrapInt(2), wrapInt(1)); - sos.put(wrapInt(3), wrapInt(1)); - sos.put(wrapInt(4), wrapInt(1)); - - return sos; - } - - protected SortedOplogSetImpl createSoplogSet(String name) throws IOException { - SortedOplogFactory factory = new NoFileSortedOplogFactory(name); - Compactor compactor = new NonCompactor(name, new File(".")); - - return new SortedOplogSetImpl(factory, Executors.newSingleThreadExecutor(), compactor); - } - - protected void flushAndWait(FlushCounter handler, SortedOplogSet sos) - throws InterruptedException, IOException { - sos.flush(null, handler); - while (sos.unflushedSize() > 0) { - Thread.sleep(1000); - } - } - - protected static class FlushCounter implements FlushHandler { - private final AtomicInteger flushes = new AtomicInteger(0); - private final AtomicBoolean error = new AtomicBoolean(false); - - @Override - public void complete() { - logger.debug("Flush complete! {}", this); - assertFalse(error.get()); - flushes.incrementAndGet(); - } - - @Override - public void error(Throwable t) { - if (!error.get()) { - t.printStackTrace(); - fail(t.getMessage()); - } - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedReaderTestCase.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedReaderTestCase.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedReaderTestCase.java deleted file mode 100644 index b41e6ba..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/SortedReaderTestCase.java +++ /dev/null @@ -1,295 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog; - -import java.io.File; -import java.io.FilenameFilter; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.NavigableMap; -import java.util.TreeMap; -import java.util.concurrent.Callable; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; - -import junit.framework.TestCase; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedReader.SortedIterator; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedReader.SortedStatistics; - -public abstract class SortedReaderTestCase extends TestCase { - private NavigableMap data; - protected SortedReader reader; - - public static void assertEquals(byte[] expected, ByteBuffer actual) { - assertEquals(expected.length, actual.remaining()); - for (int i = 0; i < expected.length; i++) { - assertEquals(expected[i], actual.get(actual.position() + i)); - } - } - - public void testComparator() { - assertNotNull(reader.getComparator()); - } - - public void testStatistics() throws IOException { - SortedStatistics stats = reader.getStatistics(); - try { - assertEquals(data.size(), stats.keyCount()); - assertTrue(Arrays.equals(data.firstKey(), stats.firstKey())); - assertTrue(Arrays.equals(data.lastKey(), stats.lastKey())); - - int keySize = 0; - int valSize = 0; - for (Entry entry : data.entrySet()) { - keySize += entry.getKey().length; - valSize += entry.getValue().length; - } - - double avgKey = keySize / data.size(); - double avgVal = valSize / data.size(); - - assertEquals(avgVal, stats.avgValueSize()); - assertEquals(avgKey, stats.avgKeySize()); - - } finally { - stats.close(); - } - } - - public void testMightContain() throws IOException { - for (byte[] key : data.keySet()) { - assertTrue(reader.mightContain(key)); - } - } - - public void testRead() throws IOException { - for (byte[] key : data.keySet()) { - assertEquals(data.get(key), reader.read(key)); - } - } - - public void testScan() throws IOException { - SortedIterator scan = reader.scan(); - try { - Iterator> iter = data.entrySet().iterator(); - doIter(scan, iter); - - } finally { - scan.close(); - } - } - - public void testMultithreadScan() throws Exception { - int threads = 10; - ExecutorService exec = Executors.newFixedThreadPool(threads); - List> tasks = new ArrayList>(); - for (int i = 0; i < threads; i++) { - tasks.add(new Callable() { - @Override - public Boolean call() throws Exception { - testScan(); - return true; - } - }); - } - - int i = 0; - while (i++ < 1000) { - for (Future ft : exec.invokeAll(tasks)) { - assertTrue(ft.get()); - } - } - } - - public void testScanReverse() throws IOException { - SortedIterator scan = reader.withAscending(false).scan(); - try { - Iterator> iter = data.descendingMap().entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - } - - public void testHead() throws IOException { - byte[] split = wrapInt(50); - SortedIterator scan = reader.head(split, true); - try { - Iterator> iter = data.headMap(split, true).entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - - scan = reader.head(split, false); - try { - Iterator> iter = data.headMap(split, false).entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - } - - public void testTail() throws IOException { - byte[] split = wrapInt(50); - SortedIterator scan = reader.tail(split, true); - try { - Iterator> iter = data.tailMap(split, true).entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - - scan = reader.tail(split, false); - try { - Iterator> iter = data.tailMap(split, false).entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - } - - public void testScanWithBounds() throws IOException { - byte[] lhs = wrapInt(10); - byte[] rhs = wrapInt(90); - - // [lhs,rhs) - SortedIterator scan = reader.scan(lhs, rhs); - try { - Iterator> iter = data.subMap(lhs, rhs).entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - - // (lhs,rhs) - scan = reader.scan(lhs, false, rhs, false); - try { - Iterator> iter = data.subMap(lhs, false, rhs, false).entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - - // [lhs,rhs] - scan = reader.scan(lhs, true, rhs, true); - try { - Iterator> iter = data.subMap(lhs, true, rhs, true).entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - } - - public void testReverseScanWithBounds() throws IOException { - data = data.descendingMap(); - byte[] rhs = wrapInt(10); - byte[] lhs = wrapInt(90); - - SortedReader rev = reader.withAscending(false); - - // [rhs,lhs) - SortedIterator scan = rev.scan(lhs, rhs); - try { - Iterator> iter = data.subMap(lhs, rhs).entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - - // (rhs,lhs) - scan = rev.scan(lhs, false, rhs, false); - try { - Iterator> iter = data.subMap(lhs, false, rhs, false).entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - - // [rhs,lhs] - scan = rev.scan(lhs, true, rhs, true); - try { - Iterator> iter = data.subMap(lhs, true, rhs, true).entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - } - - public void testScanEquality() throws IOException { - byte[] val = wrapInt(10); - - // [val,val] - SortedIterator scan = reader.scan(val); - try { - Iterator> iter = data.subMap(val, true, val, true).entrySet().iterator(); - doIter(scan, iter); - } finally { - scan.close(); - } - } - - public static byte[] wrapInt(int n) { - ByteBuffer buf = (ByteBuffer) ByteBuffer.allocate(4).putInt(n).flip(); - return buf.array(); - } - - public static File[] getSoplogsToDelete() { - return new File(".").listFiles(new FilenameFilter() { - @Override - public boolean accept(File dir, String name) { - return name.endsWith("soplog") || name.endsWith("crc"); - } - }); - } - - private void doIter(SortedIterator scan, Iterator> iter) { - while (scan.hasNext() || iter.hasNext()) { - Entry expected = iter.next(); - assertEquals(expected.getKey(), scan.next()); - assertEquals(expected.getValue(), scan.value()); - } - } - - @Override - protected final void setUp() throws IOException { - data = new TreeMap(new ByteComparator()); - - for (int i = 0; i < 100; i++) { - data.put(wrapInt(i), wrapInt(i)); - } - reader = createReader(data); - } - - @Override - protected void tearDown() throws IOException { - reader.close(); - for (File f : getSoplogsToDelete()) { - f.delete(); - } - } - - protected abstract SortedReader createReader(NavigableMap data) - throws IOException; -} http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/9438c8b1/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplogJUnitTest.java ---------------------------------------------------------------------- diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplogJUnitTest.java b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplogJUnitTest.java deleted file mode 100644 index b6813d7..0000000 --- a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/persistence/soplog/nofile/NoFileSortedOplogJUnitTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * 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. - */ -package com.gemstone.gemfire.internal.cache.persistence.soplog.nofile; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.Map.Entry; -import java.util.NavigableMap; - -import org.junit.experimental.categories.Category; - -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedOplog.SortedOplogWriter; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedOplogFactory.SortedOplogConfiguration; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedReader; -import com.gemstone.gemfire.internal.cache.persistence.soplog.SortedReaderTestCase; -import com.gemstone.gemfire.test.junit.categories.UnitTest; - -@Category(UnitTest.class) -public class NoFileSortedOplogJUnitTest extends SortedReaderTestCase { - private NoFileSortedOplog mfile; - - @Override - protected SortedReader createReader(NavigableMap data) throws IOException { - mfile = new NoFileSortedOplog(new SortedOplogConfiguration("nofile")); - - SortedOplogWriter wtr = mfile.createWriter(); - for (Entry entry : data.entrySet()) { - wtr.append(entry.getKey(), entry.getValue()); - } - wtr.close(null); - - return mfile.createReader(); - } -}