You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-commits@lucene.apache.org by ma...@apache.org on 2010/01/20 15:33:05 UTC

svn commit: r901213 - in /lucene/solr/branches/cloud/src: java/org/apache/solr/cloud/ZkController.java java/org/apache/solr/cloud/ZkNodeProps.java test/org/apache/solr/cloud/ZkControllerTest.java test/org/apache/solr/cloud/ZkNodePropsTest.java

Author: markrmiller
Date: Wed Jan 20 14:33:04 2010
New Revision: 901213

URL: http://svn.apache.org/viewvc?rev=901213&view=rev
Log:
don't use Data(Input|Output)Stream to read/write UTF with ZkNodeProps

Modified:
    lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java
    lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkNodeProps.java
    lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java
    lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkNodePropsTest.java

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java?rev=901213&r1=901212&r2=901213&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkController.java Wed Jan 20 14:33:04 2010
@@ -528,7 +528,7 @@
           null);
       
       ZkNodeProps props = new ZkNodeProps();
-      props.load(new DataInputStream(new ByteArrayInputStream(data)));
+      props.load(data);
       shardNameToProps.put(shardPath, props);
     }
 
@@ -568,8 +568,7 @@
     addZkShardsNode(cloudDesc.getShardId(), collection);
 
     // create node
-    ByteArrayOutputStream baos = new ByteArrayOutputStream();
-    // nocommit: could do xml
+
     ZkNodeProps props = new ZkNodeProps();
     props.put(URL_PROP, shardUrl);
 
@@ -577,12 +576,12 @@
     
     props.put(NODE_NAME, getNodeName());
 
-    props.store(baos);
+    byte[] bytes = props.store();
 
     String shardZkNodeName = hostName + ":" + localHostPort + "_"+ localHostContext + (coreName.length() == 0 ? "" : "_" + coreName);
     try {
       nodePath = zkClient.create(shardsZkPath + "/" + shardZkNodeName,
-        baos.toByteArray(), CreateMode.PERSISTENT);
+        bytes, CreateMode.PERSISTENT);
     } catch (KeeperException e) {
       // its okay if the node already exists
       if (e.code() != KeeperException.Code.NODEEXISTS) {

Modified: lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkNodeProps.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkNodeProps.java?rev=901213&r1=901212&r2=901213&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkNodeProps.java (original)
+++ lucene/solr/branches/cloud/src/java/org/apache/solr/cloud/ZkNodeProps.java Wed Jan 20 14:33:04 2010
@@ -1,10 +1,6 @@
 package org.apache.solr.cloud;
 
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
 import java.util.HashMap;
 import java.util.Set;
 import java.util.Map.Entry;
@@ -13,14 +9,8 @@
 
   private static final long serialVersionUID = 1L;
 
-  public void load(InputStream in) throws IOException {
-    DataInputStream dis = new DataInputStream(in);
-    String stringRep = null;
-    try {
-      stringRep = dis.readUTF();
-    } finally {
-      dis.close();
-    }
+  public void load(byte[] bytes) throws IOException {
+    String stringRep = new String(bytes, "UTF-8");
     String[] lines = stringRep.split("\n");
     for (String line : lines) {
       int sepIndex = line.indexOf('=');
@@ -30,18 +20,13 @@
     }
   }
 
-  public void store(OutputStream out) throws IOException {
+  public byte[] store() throws IOException {
     StringBuilder sb = new StringBuilder();
     Set<Entry<String,String>> entries = entrySet();
     for(Entry<String,String> entry : entries) {
       sb.append(entry.getKey() + "=" + entry.getValue() + "\n");
     }
-    DataOutputStream dos = new DataOutputStream(out);
-    try {
-      dos.writeUTF(sb.toString());
-    } finally {
-      dos.close();
-    }
+    return sb.toString().getBytes("UTF-8");
   }
   
   public String toString() {

Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java?rev=901213&r1=901212&r2=901213&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java (original)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkControllerTest.java Wed Jan 20 14:33:04 2010
@@ -197,16 +197,15 @@
   private void addShardToZk(SolrZkClient zkClient, String shardsPath,
       String zkNodeName, String url, String role) throws IOException,
       KeeperException, InterruptedException {
-    ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
     ZkNodeProps props = new ZkNodeProps();
     props.put(ZkController.URL_PROP, url);
     props.put(ZkController.ROLE_PROP, role);
     props.put(ZkController.NODE_NAME, TEST_NODE_NAME);
-    props.store(baos);
+    byte[] bytes = props.store();
 
     System.out.println("shards path:" + shardsPath);
-    zkClient.create(shardsPath + "/" + zkNodeName, baos.toByteArray(),
+    zkClient.create(shardsPath + "/" + zkNodeName, bytes,
         CreateMode.PERSISTENT);
   }
 

Modified: lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkNodePropsTest.java
URL: http://svn.apache.org/viewvc/lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkNodePropsTest.java?rev=901213&r1=901212&r2=901213&view=diff
==============================================================================
--- lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkNodePropsTest.java (original)
+++ lucene/solr/branches/cloud/src/test/org/apache/solr/cloud/ZkNodePropsTest.java Wed Jan 20 14:33:04 2010
@@ -27,7 +27,6 @@
 public class ZkNodePropsTest extends TestCase {
 
   public void testBasic() throws IOException {
-    ByteArrayOutputStream baos = new ByteArrayOutputStream();
 
     ZkNodeProps props = new ZkNodeProps();
     props.put("prop1", "value1");
@@ -36,10 +35,10 @@
     props.put("prop4", "value4");
     props.put("prop5", "value5");
     props.put("prop6", "value6");
-    props.store(baos);
+    byte[] bytes = props.store();
     
     ZkNodeProps props2 = new ZkNodeProps();
-    props2.load(new ByteArrayInputStream(baos.toByteArray()));
+    props2.load(bytes);
     assertEquals("value1", props2.get("prop1"));
     assertEquals("value2", props2.get("prop2"));
     assertEquals("value3", props2.get("prop3"));