Author: jbellis
Date: Sat Oct 30 22:53:22 2010
New Revision: 1029217
URL: http://svn.apache.org/viewvc?rev=1029217&view=rev
Log:
cleanup. patch by jbellis
Modified:
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/RemoveTest.java
Modified:
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/RemoveTest.java
URL:
http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/RemoveTest.java?rev=1029217&r1=1029216&r2=1029217&view=diff
==============================================================================
---
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/RemoveTest.java
(original)
+++
cassandra/branches/cassandra-0.7/test/unit/org/apache/cassandra/service/RemoveTest.java
Sat Oct 30 22:53:22 2010
@@ -1,53 +1,53 @@
/**
-* 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.
-*/
+ * 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.cassandra.service;
import java.io.IOException;
import java.net.InetAddress;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
-import static org.junit.Assert.*;
import org.apache.cassandra.CleanupHelper;
import org.apache.cassandra.Util;
import org.apache.cassandra.concurrent.Stage;
-import org.apache.cassandra.config.DatabaseDescriptor;
-import org.apache.cassandra.dht.*;
+import org.apache.cassandra.dht.IPartitioner;
+import org.apache.cassandra.dht.RandomPartitioner;
+import org.apache.cassandra.dht.Token;
import org.apache.cassandra.gms.ApplicationState;
import org.apache.cassandra.gms.Gossiper;
import org.apache.cassandra.gms.VersionedValue;
-import org.apache.cassandra.locator.AbstractReplicationStrategy;
-import org.apache.cassandra.locator.SimpleSnitch;
import org.apache.cassandra.locator.TokenMetadata;
import org.apache.cassandra.net.Message;
import org.apache.cassandra.net.MessagingService;
import org.apache.cassandra.net.sink.IMessageSink;
import org.apache.cassandra.net.sink.SinkManager;
import org.apache.cassandra.streaming.StreamUtil;
-import org.apache.cassandra.streaming.StreamRequestVerbHandler;
import org.apache.cassandra.utils.FBUtilities;
+import static org.junit.Assert.*;
+
public class RemoveTest extends CleanupHelper
{
StorageService ss = StorageService.instance;
@@ -58,7 +58,8 @@ public class RemoveTest extends CleanupH
List<InetAddress> hosts;
@Before
- public void setup() throws IOException {
+ public void setup() throws IOException
+ {
tmd.clearUnsafe();
IPartitioner partitioner = new RandomPartitioner();
@@ -73,36 +74,40 @@ public class RemoveTest extends CleanupH
MessagingService.instance.listen(FBUtilities.getLocalAddress());
Gossiper.instance.start(FBUtilities.getLocalAddress(), 1);
- for(int i = 0; i < 6; i++) {
+ for (int i = 0; i < 6; i++)
+ {
Gossiper.instance.initializeNodeUnsafe(hosts.get(i), 1);
}
}
@After
- public void tearDown() {
+ public void tearDown()
+ {
SinkManager.clearSinks();
- MessagingService.instance.shutdown();
+ MessagingService.shutdown();
ss.setPartitionerUnsafe(oldPartitioner);
}
- @Test(expected=UnsupportedOperationException.class)
- public void testBadToken() {
- final String token =
ss.getPartitioner().getTokenFactory().toString(keyTokens.get(2));
+ @Test(expected = UnsupportedOperationException.class)
+ public void testBadToken()
+ {
+ final String token =
StorageService.getPartitioner().getTokenFactory().toString(keyTokens.get(2));
ss.removeToken(token);
}
- @Test(expected=UnsupportedOperationException.class)
- public void testLocalToken() {
+ @Test(expected = UnsupportedOperationException.class)
+ public void testLocalToken()
+ {
//first token should be localhost
- final String token =
ss.getPartitioner().getTokenFactory().toString(endpointTokens.get(0));
+ final String token =
StorageService.getPartitioner().getTokenFactory().toString(endpointTokens.get(0));
ss.removeToken(token);
}
@Test
public void testRemoveToken() throws InterruptedException
{
- IPartitioner partitioner = ss.getPartitioner();
+ IPartitioner partitioner = StorageService.getPartitioner();
final String token =
partitioner.getTokenFactory().toString(endpointTokens.get(5));
ReplicationSink rSink = new ReplicationSink();
@@ -110,15 +115,15 @@ public class RemoveTest extends CleanupH
// start removal in background and send replication confirmations
final AtomicBoolean success = new AtomicBoolean(false);
- Thread remover = new Thread()
+ Thread remover = new Thread()
{
- public void run()
+ public void run()
{
- try
+ try
{
ss.removeToken(token);
}
- catch (Exception e )
+ catch (Exception e)
{
System.err.println(e);
e.printStackTrace();
@@ -134,7 +139,8 @@ public class RemoveTest extends CleanupH
assertTrue(tmd.isLeaving(hosts.get(5)));
assertEquals(1, tmd.getLeavingEndpoints().size());
- for(InetAddress host : hosts) {
+ for (InetAddress host : hosts)
+ {
Message msg = new Message(host,
StorageService.Verb.REPLICATION_FINISHED, new byte[0]);
MessagingService.instance.sendRR(msg,
FBUtilities.getLocalAddress());
}
@@ -148,7 +154,7 @@ public class RemoveTest extends CleanupH
@Test
public void testStartRemoving()
{
- IPartitioner partitioner = ss.getPartitioner();
+ IPartitioner partitioner = StorageService.getPartitioner();
VersionedValue.VersionedValueFactory valueFactory = new
VersionedValue.VersionedValueFactory(partitioner);
NotificationSink nSink = new NotificationSink();
@@ -170,7 +176,7 @@ public class RemoveTest extends CleanupH
@Test
public void testFinishRemoving()
{
- IPartitioner partitioner = ss.getPartitioner();
+ IPartitioner partitioner = StorageService.getPartitioner();
VersionedValue.VersionedValueFactory valueFactory = new
VersionedValue.VersionedValueFactory(partitioner);
assertEquals(0, tmd.getLeavingEndpoints().size());
@@ -183,10 +189,12 @@ public class RemoveTest extends CleanupH
assertFalse(tmd.isMember(hosts.get(5)));
}
- class ReplicationSink implements IMessageSink {
+ class ReplicationSink implements IMessageSink
+ {
- public Message handleMessage(Message msg, InetAddress to) {
- if(!msg.getVerb().equals(StorageService.Verb.STREAM_REQUEST))
+ public Message handleMessage(Message msg, InetAddress to)
+ {
+ if (!msg.getVerb().equals(StorageService.Verb.STREAM_REQUEST))
return msg;
StreamUtil.finishStreamRequest(msg, to);
@@ -195,16 +203,18 @@ public class RemoveTest extends CleanupH
}
}
- class NotificationSink implements IMessageSink {
+ class NotificationSink implements IMessageSink
+ {
public int callCount = 0;
- public Message handleMessage(Message msg, InetAddress to) {
- if(msg.getVerb().equals(StorageService.Verb.REPLICATION_FINISHED))
+ public Message handleMessage(Message msg, InetAddress to)
+ {
+ if (msg.getVerb().equals(StorageService.Verb.REPLICATION_FINISHED))
{
callCount++;
assertEquals(Stage.MISC, msg.getMessageType());
// simulate a response from remote server
- Message response = msg.getReply(FBUtilities.getLocalAddress(),
new byte[]{});
+ Message response = msg.getReply(FBUtilities.getLocalAddress(),
new byte[]{ });
MessagingService.instance.sendOneWay(response,
FBUtilities.getLocalAddress());
return null;
}