package org.apache.cassandra.service; /* * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * */ import java.util.Arrays; import org.apache.cassandra.SchemaLoader; import org.junit.Test; import org.apache.cassandra.db.ColumnFamily; import static org.apache.cassandra.db.TableTest.assertColumns; import static org.apache.cassandra.Util.column; import static junit.framework.Assert.assertNull; public class RowResolverTest extends SchemaLoader { @Test public void testResolveSupersetNewer() { ColumnFamily cf1 = ColumnFamily.create("Keyspace1", "Standard1"); cf1.addColumn(column("c1", "v1", 0)); ColumnFamily cf2 = ColumnFamily.create("Keyspace1", "Standard1"); cf2.addColumn(column("c1", "v2", 1)); ColumnFamily resolved = RowRepairResolver.resolveSuperset(Arrays.asList(cf1, cf2)); assertColumns(resolved, "c1"); assertColumns(ColumnFamily.diff(cf1, resolved), "c1"); assertNull(ColumnFamily.diff(cf2, resolved)); } @Test public void testResolveSupersetDisjoint() { ColumnFamily cf1 = ColumnFamily.create("Keyspace1", "Standard1"); cf1.addColumn(column("c1", "v1", 0)); ColumnFamily cf2 = ColumnFamily.create("Keyspace1", "Standard1"); cf2.addColumn(column("c2", "v2", 1)); ColumnFamily resolved = RowRepairResolver.resolveSuperset(Arrays.asList(cf1, cf2)); assertColumns(resolved, "c1", "c2"); assertColumns(ColumnFamily.diff(cf1, resolved), "c2"); assertColumns(ColumnFamily.diff(cf2, resolved), "c1"); } @Test public void testResolveSupersetNullOne() { ColumnFamily cf2 = ColumnFamily.create("Keyspace1", "Standard1"); cf2.addColumn(column("c2", "v2", 1)); ColumnFamily resolved = RowRepairResolver.resolveSuperset(Arrays.asList(null, cf2)); assertColumns(resolved, "c2"); assertColumns(ColumnFamily.diff(null, resolved), "c2"); assertNull(ColumnFamily.diff(cf2, resolved)); } @Test public void testResolveSupersetNullTwo() { ColumnFamily cf1 = ColumnFamily.create("Keyspace1", "Standard1"); cf1.addColumn(column("c1", "v1", 0)); ColumnFamily resolved = RowRepairResolver.resolveSuperset(Arrays.asList(cf1, null)); assertColumns(resolved, "c1"); assertNull(ColumnFamily.diff(cf1, resolved)); assertColumns(ColumnFamily.diff(null, resolved), "c1"); } @Test public void testResolveSupersetNullBoth() { assertNull(RowRepairResolver.resolveSuperset(Arrays.<ColumnFamily>asList(null, null))); } }