Author: jbellis
Date: Fri Aug  7 23:29:50 2009
New Revision: 802267

URL: http://svn.apache.org/viewvc?rev=802267&view=rev
Log:
fix broken casts.  patch by Bill de hOra; reviewed by jbellis for CASSANDRA-338

Added:
    
incubator/cassandra/trunk/test/unit/org/apache/cassandra/service/StorageServiceTest.java
Modified:
    
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java

Modified: 
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
URL: 
http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java?rev=802267&r1=802266&r2=802267&view=diff
==============================================================================
--- 
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
 (original)
+++ 
incubator/cassandra/trunk/src/java/org/apache/cassandra/service/StorageService.java
 Fri Aug  7 23:29:50 2009
@@ -683,9 +683,11 @@
         {
             EndPoint target = new EndPoint(host, 
DatabaseDescriptor.getStoragePort());
             /* Set up the stream manager with the files that need to streamed 
*/
-            
StreamManager.instance(target).addFilesToStream((StreamContextManager.StreamContext[])
 streamContexts.toArray());
+            final StreamContextManager.StreamContext[] contexts = 
streamContexts.toArray(new 
StreamContextManager.StreamContext[streamContexts.size()]);
+            StreamManager.instance(target).addFilesToStream(contexts);
             /* Send the bootstrap initiate message */
-            BootstrapInitiateMessage biMessage = new 
BootstrapInitiateMessage((StreamContextManager.StreamContext[]) 
streamContexts.toArray());
+            final StreamContextManager.StreamContext[] bootContexts = 
streamContexts.toArray(new 
StreamContextManager.StreamContext[streamContexts.size()]);
+            BootstrapInitiateMessage biMessage = new 
BootstrapInitiateMessage(bootContexts);
             Message message = 
BootstrapInitiateMessage.makeBootstrapInitiateMessage(biMessage);
             if (logger_.isDebugEnabled())
               logger_.debug("Sending a bootstrap initiate message to " + 
target + " ...");

Added: 
incubator/cassandra/trunk/test/unit/org/apache/cassandra/service/StorageServiceTest.java
URL: 
http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/service/StorageServiceTest.java?rev=802267&view=auto
==============================================================================
--- 
incubator/cassandra/trunk/test/unit/org/apache/cassandra/service/StorageServiceTest.java
 (added)
+++ 
incubator/cassandra/trunk/test/unit/org/apache/cassandra/service/StorageServiceTest.java
 Fri Aug  7 23:29:50 2009
@@ -0,0 +1,56 @@
+/*
+* 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 org.junit.Test;
+import org.junit.Assert;
+import org.apache.cassandra.net.io.StreamContextManager;
+
+import java.util.List;
+import java.util.ArrayList;
+
+public class StorageServiceTest {
+
+
+    @Test
+    public void testImpossibleCast() {
+        List<StreamContextManager.StreamContext> streamContexts = new 
ArrayList<StreamContextManager.StreamContext>();
+        try {
+            StreamContextManager.StreamContext[] arr = 
(StreamContextManager.StreamContext[]) streamContexts.toArray();
+            Assert.fail("expected ClassCastException from Object[] to 
StreamContextManager.StreamContext[]");
+
+        } catch (ClassCastException e) {
+            Assert.assertTrue(true);
+        }
+    }
+
+
+    @Test
+    public void testPossibleCast() {
+
+        List<StreamContextManager.StreamContext> streamContexts = new 
ArrayList<StreamContextManager.StreamContext>();
+        StreamContextManager.StreamContext[] contexts = 
streamContexts.toArray(new 
StreamContextManager.StreamContext[streamContexts.size()]);
+        Assert.assertTrue(contexts.length == 0);
+
+        StreamContextManager.StreamContext streamContext = new 
StreamContextManager.StreamContext("foofile", 0, "fooTable");
+        streamContexts.add(streamContext);
+        contexts = streamContexts.toArray(new 
StreamContextManager.StreamContext[streamContexts.size()]);
+        Assert.assertTrue(contexts.length == 1);
+    }
+}


Reply via email to