use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class GossiperTest method testReloadSeeds.
// Note: This test might fail if for some reason the node broadcast address is in 127.99.0.0/16
@Test
public void testReloadSeeds() throws UnknownHostException {
Gossiper gossiper = new Gossiper(false);
List<String> loadedList;
// Initialize the seed list directly to a known set to start with
gossiper.seeds.clear();
InetAddressAndPort addr = InetAddressAndPort.getByAddress(InetAddress.getByName("127.99.1.1"));
int nextSize = 4;
List<InetAddressAndPort> nextSeeds = new ArrayList<>(nextSize);
for (int i = 0; i < nextSize; i++) {
gossiper.seeds.add(addr);
nextSeeds.add(addr);
addr = InetAddressAndPort.getByAddress(InetAddresses.increment(addr.getAddress()));
}
Assert.assertEquals(nextSize, gossiper.seeds.size());
// Add another unique address to the list
addr = InetAddressAndPort.getByAddress(InetAddresses.increment(addr.getAddress()));
nextSeeds.add(addr);
nextSize++;
DatabaseDescriptor.setSeedProvider(new TestSeedProvider(nextSeeds));
loadedList = gossiper.reloadSeeds();
// Check that the new entry was added
Assert.assertEquals(nextSize, loadedList.size());
for (InetAddressAndPort a : nextSeeds) assertTrue(loadedList.contains(a.toString()));
// Check that the return value of the reloadSeeds matches the content of the getSeeds call
// and that they both match the internal contents of the Gossiper seeds list
Assert.assertEquals(loadedList.size(), gossiper.getSeeds().size());
for (InetAddressAndPort a : gossiper.seeds) {
assertTrue(loadedList.contains(a.toString()));
assertTrue(gossiper.getSeeds().contains(a.toString()));
}
// Add a duplicate of the last address to the seed provider list
int uniqueSize = nextSize;
nextSeeds.add(addr);
nextSize++;
DatabaseDescriptor.setSeedProvider(new TestSeedProvider(nextSeeds));
loadedList = gossiper.reloadSeeds();
// Check that the number of seed nodes reported hasn't increased
Assert.assertEquals(uniqueSize, loadedList.size());
for (InetAddressAndPort a : nextSeeds) assertTrue(loadedList.contains(a.toString()));
// Create a new list that has no overlaps with the previous list
addr = InetAddressAndPort.getByAddress(InetAddress.getByName("127.99.2.1"));
int disjointSize = 3;
List<InetAddressAndPort> disjointSeeds = new ArrayList<>(disjointSize);
for (int i = 0; i < disjointSize; i++) {
disjointSeeds.add(addr);
addr = InetAddressAndPort.getByAddress(InetAddresses.increment(addr.getAddress()));
}
DatabaseDescriptor.setSeedProvider(new TestSeedProvider(disjointSeeds));
loadedList = gossiper.reloadSeeds();
// Check that the list now contains exactly the new other list.
Assert.assertEquals(disjointSize, gossiper.getSeeds().size());
Assert.assertEquals(disjointSize, loadedList.size());
for (InetAddressAndPort a : disjointSeeds) {
assertTrue(gossiper.getSeeds().contains(a.toString()));
assertTrue(loadedList.contains(a.toString()));
}
// Set the seed node provider to return an empty list
DatabaseDescriptor.setSeedProvider(new TestSeedProvider(new ArrayList<InetAddressAndPort>()));
loadedList = gossiper.reloadSeeds();
// Check that the in memory seed node list was not modified
Assert.assertEquals(disjointSize, loadedList.size());
for (InetAddressAndPort a : disjointSeeds) assertTrue(loadedList.contains(a.toString()));
// Change the seed provider to one that throws an unchecked exception
DatabaseDescriptor.setSeedProvider(new ErrorSeedProvider());
loadedList = gossiper.reloadSeeds();
// Check for the expected null response from a reload error
assertNull(loadedList);
// Check that the in memory seed node list was not modified and the exception was caught
Assert.assertEquals(disjointSize, gossiper.getSeeds().size());
for (InetAddressAndPort a : disjointSeeds) assertTrue(gossiper.getSeeds().contains(a.toString()));
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class SerializationsTest method testGossipDigestWrite.
private void testGossipDigestWrite() throws IOException {
Map<InetAddressAndPort, EndpointState> states = new HashMap<>();
states.put(InetAddressAndPort.getByName("127.0.0.1"), Statics.EndpointSt);
states.put(InetAddressAndPort.getByName("127.0.0.2"), Statics.EndpointSt);
GossipDigestAck ack = new GossipDigestAck(Statics.Digests, states);
GossipDigestAck2 ack2 = new GossipDigestAck2(states);
GossipDigestSyn syn = new GossipDigestSyn("Not a real cluster name", StorageService.instance.getTokenMetadata().partitioner.getClass().getCanonicalName(), Statics.Digests);
DataOutputStreamPlus out = getOutput("gms.Gossip.bin");
for (GossipDigest gd : Statics.Digests) GossipDigest.serializer.serialize(gd, out, getVersion());
GossipDigestAck.serializer.serialize(ack, out, getVersion());
GossipDigestAck2.serializer.serialize(ack2, out, getVersion());
GossipDigestSyn.serializer.serialize(syn, out, getVersion());
out.close();
// test serializedSize
for (GossipDigest gd : Statics.Digests) testSerializedSize(gd, GossipDigest.serializer);
testSerializedSize(ack, GossipDigestAck.serializer);
testSerializedSize(ack2, GossipDigestAck2.serializer);
testSerializedSize(syn, GossipDigestSyn.serializer);
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class CassandraGenerators method toStringRecursive.
/**
* Uses reflection to generate a toString. This method is aware of common Cassandra classes and can be used for
* generators or tests to provide more details for debugging.
*/
public static String toStringRecursive(Object o) {
return ReflectionToStringBuilder.toString(o, new MultilineRecursiveToStringStyle() {
private String spacer = "";
{
// common lang uses start/end chars that are not the common ones used, so switch to the common ones
setArrayStart("[");
setArrayEnd("]");
setContentStart("{");
setContentEnd("}");
setUseIdentityHashCode(false);
setUseShortClassName(true);
}
protected boolean accept(Class<?> clazz) {
return // toString enums
!clazz.isEnum() && // if no fields, just toString
Stream.of(clazz.getDeclaredFields()).anyMatch(f -> !Modifier.isStatic(f.getModifiers()));
}
public void appendDetail(StringBuffer buffer, String fieldName, Object value) {
if (value instanceof ByteBuffer) {
value = ByteBufferUtil.bytesToHex((ByteBuffer) value);
} else if (value instanceof AbstractType) {
value = SchemaCQLHelper.toCqlType((AbstractType) value);
} else if (value instanceof Token || value instanceof InetAddressAndPort || value instanceof FieldIdentifier) {
value = value.toString();
} else if (value instanceof TableMetadata) {
// to make sure the correct indents are taken, convert to CQL, then replace newlines with the indents
// then prefix with the indents.
String cql = SchemaCQLHelper.getTableMetadataAsCQL((TableMetadata) value);
cql = NEWLINE_PATTERN.matcher(cql).replaceAll(Matcher.quoteReplacement("\n " + spacer));
cql = "\n " + spacer + cql;
value = cql;
}
super.appendDetail(buffer, fieldName, value);
}
// MultilineRecursiveToStringStyle doesn't look at what was set and instead hard codes the values when it "resets" the level
protected void setArrayStart(String arrayStart) {
super.setArrayStart(arrayStart.replace("{", "["));
}
protected void setArrayEnd(String arrayEnd) {
super.setArrayEnd(arrayEnd.replace("}", "]"));
}
protected void setContentStart(String contentStart) {
// use this to infer the spacer since it isn't exposed.
String[] split = contentStart.split("\n", 2);
spacer = split.length == 2 ? split[1] : "";
super.setContentStart(contentStart.replace("[", "{"));
}
protected void setContentEnd(String contentEnd) {
super.setContentEnd(contentEnd.replace("]", "}"));
}
}, true);
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class ValidatorTest method testValidatorFailed.
@Test
public void testValidatorFailed() throws Throwable {
Range<Token> range = new Range<>(partitioner.getMinimumToken(), partitioner.getRandomToken());
final RepairJobDesc desc = new RepairJobDesc(UUID.randomUUID(), UUID.randomUUID(), keyspace, columnFamily, Arrays.asList(range));
final CompletableFuture<Message> outgoingMessageSink = registerOutgoingMessageSink();
InetAddressAndPort remote = InetAddressAndPort.getByName("127.0.0.2");
Validator validator = new Validator(desc, remote, 0, PreviewKind.NONE);
validator.fail();
Message message = outgoingMessageSink.get(TEST_TIMEOUT, TimeUnit.SECONDS);
assertEquals(Verb.VALIDATION_RSP, message.verb());
ValidationResponse m = (ValidationResponse) message.payload;
assertEquals(desc, m.desc);
assertFalse(m.success());
assertNull(m.trees);
}
use of org.apache.cassandra.locator.InetAddressAndPort in project cassandra by apache.
the class ValidatorTest method testValidatorComplete.
@Test
public void testValidatorComplete() throws Throwable {
Range<Token> range = new Range<>(partitioner.getMinimumToken(), partitioner.getRandomToken());
final RepairJobDesc desc = new RepairJobDesc(UUID.randomUUID(), UUID.randomUUID(), keyspace, columnFamily, Arrays.asList(range));
final CompletableFuture<Message> outgoingMessageSink = registerOutgoingMessageSink();
InetAddressAndPort remote = InetAddressAndPort.getByName("127.0.0.2");
ColumnFamilyStore cfs = Keyspace.open(keyspace).getColumnFamilyStore(columnFamily);
Validator validator = new Validator(desc, remote, 0, PreviewKind.NONE);
MerkleTrees trees = new MerkleTrees(partitioner);
trees.addMerkleTrees((int) Math.pow(2, 15), validator.desc.ranges);
validator.prepare(cfs, trees);
// and confirm that the trees were split
assertTrue(trees.size() > 1);
// add a row
Token mid = partitioner.midpoint(range.left, range.right);
validator.add(EmptyIterators.unfilteredRow(cfs.metadata(), new BufferDecoratedKey(mid, ByteBufferUtil.bytes("inconceivable!")), false));
validator.complete();
// confirm that the trees were validated
Token min = trees.partitioner().getMinimumToken();
assertNotNull(trees.hash(new Range<>(min, min)));
Message message = outgoingMessageSink.get(TEST_TIMEOUT, TimeUnit.SECONDS);
assertEquals(Verb.VALIDATION_RSP, message.verb());
ValidationResponse m = (ValidationResponse) message.payload;
assertEquals(desc, m.desc);
assertTrue(m.success());
assertNotNull(m.trees);
}
Aggregations