Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: BrandwatchLtd/bw-lucene-solr
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: d9f9739335de9c7423bd479d72649d107300e1bd
Choose a base ref
..
head repository: BrandwatchLtd/bw-lucene-solr
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: a66f24589a3255b405e634a62be4406c88c93dc4
Choose a head ref
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package org.apache.solr.search.facet;

import org.apache.lucene.util.LuceneTestCase;
import org.junit.Test;

public class BitmapFrequencyCounterTest extends LuceneTestCase {
private static final int TEST_ORDINAL = 5;

@Test(expected = NegativeArraySizeException.class)
public void givenNegativeSize_whenConstructingCounter() {
new BitmapFrequencyCounter(-1);
}

@Test
public void givenSize0_whenAddingValue_withFrequency1() {
BitmapFrequencyCounter counter = new BitmapFrequencyCounter(0);

counter.add(TEST_ORDINAL);

assertEquals(counter.getBitmaps().length, 0);
assertTrue(counter.getOverflow().contains(TEST_ORDINAL));
}

@Test
public void givenSize0_whenAddingValue_withFrequency2() {
BitmapFrequencyCounter counter = new BitmapFrequencyCounter(0);

counter.add(TEST_ORDINAL);
counter.add(TEST_ORDINAL);

assertEquals(counter.getBitmaps().length, 0);
assertTrue(counter.getOverflow().contains(TEST_ORDINAL));
}

@Test
public void givenSize1_whenAddingValue_withFrequency1() {
BitmapFrequencyCounter counter = new BitmapFrequencyCounter(1);

counter.add(TEST_ORDINAL);

assertEquals(counter.getBitmaps().length, 1);
assertTrue(counter.getBitmaps()[0].contains(TEST_ORDINAL));
assertNull(counter.getOverflow());
}

@Test
public void givenSize1_whenAddingValue_withFrequency2() {
BitmapFrequencyCounter counter = new BitmapFrequencyCounter(1);

counter.add(TEST_ORDINAL);
counter.add(TEST_ORDINAL);

assertEquals(counter.getBitmaps().length, 1);
assertFalse(counter.getBitmaps()[0].contains(TEST_ORDINAL));
assertTrue(counter.getOverflow().contains(TEST_ORDINAL));
}

@Test
public void givenSize2_whenAddingValue_withFrequency1() {
BitmapFrequencyCounter counter = new BitmapFrequencyCounter(2);

counter.add(TEST_ORDINAL);

assertEquals(counter.getBitmaps().length, 2);
assertTrue(counter.getBitmaps()[0].contains(TEST_ORDINAL));
assertNull(counter.getOverflow());
}

@Test
public void givenSize2_whenAddingValue_withFrequency2() {
BitmapFrequencyCounter counter = new BitmapFrequencyCounter(2);

counter.add(TEST_ORDINAL);
counter.add(TEST_ORDINAL);

assertEquals(counter.getBitmaps().length, 2);
assertFalse(counter.getBitmaps()[0].contains(TEST_ORDINAL));
assertTrue(counter.getBitmaps()[1].contains(TEST_ORDINAL));
assertNull(counter.getOverflow());
}

@Test
public void givenSize2_whenAddingValue_withFrequency3() {
BitmapFrequencyCounter counter = new BitmapFrequencyCounter(2);

counter.add(TEST_ORDINAL);
counter.add(TEST_ORDINAL);
counter.add(TEST_ORDINAL);

assertEquals(counter.getBitmaps().length, 2);
assertTrue(counter.getBitmaps()[0].contains(TEST_ORDINAL));
assertTrue(counter.getBitmaps()[1].contains(TEST_ORDINAL));
assertNull(counter.getOverflow());
}

@Test
public void givenSize2_whenAddingValue_withFrequency4() {
BitmapFrequencyCounter counter = new BitmapFrequencyCounter(2);

counter.add(TEST_ORDINAL);
counter.add(TEST_ORDINAL);
counter.add(TEST_ORDINAL);
counter.add(TEST_ORDINAL);

assertEquals(counter.getBitmaps().length, 2);
assertFalse(counter.getBitmaps()[0].contains(TEST_ORDINAL));
assertFalse(counter.getBitmaps()[1].contains(TEST_ORDINAL));
assertTrue(counter.getOverflow().contains(TEST_ORDINAL));
}

@Test
public void givenSize2_whenMergingValues() {
BitmapFrequencyCounter x = new BitmapFrequencyCounter(2);
BitmapFrequencyCounter y = new BitmapFrequencyCounter(2);

x.add(TEST_ORDINAL);
x.add(TEST_ORDINAL);

assertEquals(x.getBitmaps().length, 2);
assertFalse(x.getBitmaps()[0].contains(TEST_ORDINAL));
assertTrue(x.getBitmaps()[1].contains(TEST_ORDINAL));
assertNull(x.getOverflow());

y.add(TEST_ORDINAL);
y.add(TEST_ORDINAL);

assertEquals(y.getBitmaps().length, 2);
assertFalse(y.getBitmaps()[0].contains(TEST_ORDINAL));
assertTrue(y.getBitmaps()[1].contains(TEST_ORDINAL));
assertNull(y.getOverflow());

x = x.merge(y);

assertEquals(x.getBitmaps().length, 2);
assertFalse(x.getBitmaps()[0].contains(TEST_ORDINAL));
assertFalse(x.getBitmaps()[1].contains(TEST_ORDINAL));
assertTrue(x.getOverflow().contains(TEST_ORDINAL));
}

@Test
public void givenSize4_whenMergingValues() {
BitmapFrequencyCounter x = new BitmapFrequencyCounter(4);
BitmapFrequencyCounter y = new BitmapFrequencyCounter(4);

x.add(TEST_ORDINAL);
x.add(TEST_ORDINAL);
x.add(TEST_ORDINAL);
x.add(TEST_ORDINAL);
x.add(TEST_ORDINAL);
x.add(TEST_ORDINAL);
x.add(TEST_ORDINAL);
x.add(TEST_ORDINAL);
x.add(TEST_ORDINAL);
x.add(TEST_ORDINAL);

assertEquals(x.getBitmaps().length, 4);
assertFalse(x.getBitmaps()[0].contains(TEST_ORDINAL));
assertTrue(x.getBitmaps()[1].contains(TEST_ORDINAL));
assertFalse(x.getBitmaps()[2].contains(TEST_ORDINAL));
assertTrue(x.getBitmaps()[3].contains(TEST_ORDINAL));
assertNull(x.getOverflow());

y.add(TEST_ORDINAL);
y.add(TEST_ORDINAL);
y.add(TEST_ORDINAL);
y.add(TEST_ORDINAL);
y.add(TEST_ORDINAL);

assertEquals(y.getBitmaps().length, 4);
assertTrue(y.getBitmaps()[0].contains(TEST_ORDINAL));
assertFalse(y.getBitmaps()[1].contains(TEST_ORDINAL));
assertTrue(y.getBitmaps()[2].contains(TEST_ORDINAL));
assertNull(y.getBitmaps()[3]);
assertNull(y.getOverflow());

x = x.merge(y);

assertEquals(x.getBitmaps().length, 4);
assertTrue(x.getBitmaps()[0].contains(TEST_ORDINAL));
assertTrue(x.getBitmaps()[1].contains(TEST_ORDINAL));
assertTrue(x.getBitmaps()[2].contains(TEST_ORDINAL));
assertTrue(x.getBitmaps()[3].contains(TEST_ORDINAL));
assertNull(y.getOverflow());
}
}
Original file line number Diff line number Diff line change
@@ -16,9 +16,6 @@
*/
package org.apache.solr.update.processor;

import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.not;

import java.io.IOException;
import java.time.ZonedDateTime;
import java.util.Arrays;
@@ -29,7 +26,8 @@
import java.util.function.Function;
import java.util.stream.Collectors;

import org.apache.curator.shaded.com.google.common.collect.Lists;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.solr.EmbeddedSolrServerTestBase;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
@@ -40,7 +38,8 @@
import org.junit.Ignore;
import org.junit.Test;

import com.google.common.collect.ImmutableMap;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.not;

public abstract class AbstractAtomicUpdatesMultivalueTestBase extends EmbeddedSolrServerTestBase {

Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
/*
* 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 org.apache.solr;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;

import org.apache.commons.io.FileUtils;
import org.apache.lucene.util.LuceneTestCase;
import org.apache.solr.client.solrj.embedded.EmbeddedSolrServer;
import org.apache.solr.common.util.ContentStream;
import org.apache.solr.common.util.ContentStreamBase;
import org.apache.solr.common.util.ContentStreamBase.ByteArrayStream;
import org.apache.solr.util.ExternalPaths;
import org.junit.After;
import org.junit.AfterClass;

import com.google.common.io.ByteStreams;

abstract public class EmbeddedSolrServerTestBase extends SolrTestCaseJ4 {

protected static final String DEFAULT_CORE_NAME = "collection1";

public static EmbeddedSolrServer client = null;

@After
public synchronized void afterClass() throws Exception {
if (client != null) client.close();
client = null;
}

@AfterClass
public static void afterEmbeddedSolrServerTestBase() throws Exception {

}

public synchronized EmbeddedSolrServer getSolrClient() {
if (client == null) {
client = createNewSolrClient();
}
return client;
}

/**
* Create a new solr client. Subclasses should override for other options.
*/
public EmbeddedSolrServer createNewSolrClient() {
return new EmbeddedSolrServer(h.getCoreContainer(), DEFAULT_CORE_NAME) {
@Override
public void close() {
// do not close core container
}
};
}

public void upload(final String collection, final ContentStream... contents) {
final Path base = Paths.get(getSolrClient().getCoreContainer().getSolrHome(), collection);
writeTo(base, contents);
}

private void writeTo(final Path base, final ContentStream... contents) {
try {
if (!Files.exists(base)) {
Files.createDirectories(base);
}

for (final ContentStream content : contents) {
final File file = new File(base.toFile(), content.getName());
file.getParentFile().mkdirs();

try (OutputStream os = new FileOutputStream(file)) {
ByteStreams.copy(content.getStream(), os);
}
}
} catch (final IOException e) {
throw new RuntimeException(e);
}
}

public Collection<ContentStream> download(final String collection, final String... names) {
final Path base = Paths.get(getSolrClient().getCoreContainer().getSolrHome(), collection);
final List<ContentStream> result = new ArrayList<>();

if (Files.exists(base)) {
for (final String name : names) {
final File file = new File(base.toFile(), name);
if (file.exists() && file.canRead()) {
try {
final ByteArrayOutputStream os = new ByteArrayOutputStream();
ByteStreams.copy(new FileInputStream(file), os);
final ByteArrayStream stream = new ContentStreamBase.ByteArrayStream(os.toByteArray(), name);
result.add(stream);
} catch (final IOException e) {
throw new RuntimeException(e);
}
}
}
}

return result;
}

public static void initCore() throws Exception {
final String home = legacyExampleCollection1SolrHome();
final String config = home + "/" + DEFAULT_CORE_NAME + "/conf/solrconfig.xml";
final String schema = home + "/" + DEFAULT_CORE_NAME + "/conf/schema.xml";
initCore(config, schema, home);
}

public static String legacyExampleCollection1SolrHome() throws IOException {
final String sourceHome = ExternalPaths.SOURCE_HOME;
if (sourceHome == null)
throw new IllegalStateException("No source home! Cannot create the legacy example solr home directory.");

final File tempSolrHome = LuceneTestCase.createTempDir().toFile();
FileUtils.copyFileToDirectory(new File(sourceHome, "server/solr/solr.xml"), tempSolrHome);
final File collectionDir = new File(tempSolrHome, DEFAULT_CORE_NAME);
FileUtils.forceMkdir(collectionDir);
final File configSetDir = new File(sourceHome, "server/solr/configsets/sample_techproducts_configs/conf");
FileUtils.copyDirectoryToDirectory(configSetDir, collectionDir);

final Properties props = new Properties();
props.setProperty("name", DEFAULT_CORE_NAME);

try (Writer writer = new OutputStreamWriter(FileUtils.openOutputStream(new File(collectionDir, "core.properties")),
"UTF-8");) {
props.store(writer, null);
}

return tempSolrHome.getAbsolutePath();
}

}