accumulo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ktur...@apache.org
Subject svn commit: r1396243 - in /accumulo/trunk/core: ./ src/main/java/org/apache/accumulo/core/client/mock/ src/test/java/org/apache/accumulo/core/client/mock/
Date Tue, 09 Oct 2012 19:52:14 GMT
Author: kturner
Date: Tue Oct  9 19:52:14 2012
New Revision: 1396243

URL: http://svn.apache.org/viewvc?rev=1396243&view=rev
Log:
ACCUMULO-782 applied patch from Ed Kohlwey to make mock Accumulo return instance it was created
with (merged from 1.4)

Modified:
    accumulo/trunk/core/   (props changed)
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java
    accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java
    accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockConnectorTest.java

Propchange: accumulo/trunk/core/
------------------------------------------------------------------------------
  Merged /accumulo/branches/1.4/src/core:r1396227

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java?rev=1396243&r1=1396242&r2=1396243&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockConnector.java
Tue Oct  9 19:52:14 2012
@@ -36,16 +36,18 @@ public class MockConnector extends Conne
   
   String username;
   private final MockAccumulo acu;
+  private final Instance instance;
   
-  MockConnector(String username) {
-    this(username, new MockAccumulo());
+  MockConnector(String username, Instance instance) {
+    this(username, new MockAccumulo(), instance);
   }
   
   @SuppressWarnings("deprecation")
   // Not really deprecated, just discouraging client use.
-  MockConnector(String username, MockAccumulo acu) {
+  MockConnector(String username, MockAccumulo acu, Instance instance) {
     this.username = username;
     this.acu = acu;
+    this.instance = instance;
   }
   
   @Override
@@ -102,7 +104,7 @@ public class MockConnector extends Conne
   
   @Override
   public Instance getInstance() {
-    return new MockInstance();
+    return instance;
   }
   
   @Override

Modified: accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java?rev=1396243&r1=1396242&r2=1396243&view=diff
==============================================================================
--- accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java
(original)
+++ accumulo/trunk/core/src/main/java/org/apache/accumulo/core/client/mock/MockInstance.java
Tue Oct  9 19:52:14 2012
@@ -87,7 +87,7 @@ public class MockInstance implements Ins
   
   @Override
   public Connector getConnector(String user, byte[] pass) throws AccumuloException, AccumuloSecurityException
{
-    Connector conn = new MockConnector(user, acu);
+    Connector conn = new MockConnector(user, acu, this);
     conn.securityOperations().createUser(user, pass, new Authorizations());
     return conn;
   }

Modified: accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockConnectorTest.java
URL: http://svn.apache.org/viewvc/accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockConnectorTest.java?rev=1396243&r1=1396242&r2=1396243&view=diff
==============================================================================
--- accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockConnectorTest.java
(original)
+++ accumulo/trunk/core/src/test/java/org/apache/accumulo/core/client/mock/MockConnectorTest.java
Tue Oct  9 19:52:14 2012
@@ -25,12 +25,17 @@ import java.util.Iterator;
 import java.util.Map.Entry;
 import java.util.Random;
 
+import junit.framework.Assert;
+
 import org.apache.accumulo.core.Constants;
+import org.apache.accumulo.core.client.AccumuloException;
+import org.apache.accumulo.core.client.AccumuloSecurityException;
 import org.apache.accumulo.core.client.BatchDeleter;
 import org.apache.accumulo.core.client.BatchScanner;
 import org.apache.accumulo.core.client.BatchWriter;
 import org.apache.accumulo.core.client.BatchWriterConfig;
 import org.apache.accumulo.core.client.Connector;
+import org.apache.accumulo.core.client.Instance;
 import org.apache.accumulo.core.client.IteratorSetting;
 import org.apache.accumulo.core.client.MultiTableBatchWriter;
 import org.apache.accumulo.core.client.Scanner;
@@ -53,7 +58,7 @@ public class MockConnectorTest {
   
   @Test
   public void testSunnyDay() throws Exception {
-    Connector c = new MockConnector("root");
+    Connector c = new MockConnector("root", new MockInstance());
     c.tableOperations().create("test");
     BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
     for (int i = 0; i < 100; i++) {
@@ -79,7 +84,7 @@ public class MockConnectorTest {
   
   @Test
   public void testChangeAuths() throws Exception {
-    Connector c = new MockConnector("root");
+    Connector c = new MockConnector("root", new MockInstance());
     c.securityOperations().createUser("greg", new byte[] {}, new Authorizations("A", "B",
"C"));
     assertTrue(c.securityOperations().getUserAuthorizations("greg").contains("A".getBytes()));
     c.securityOperations().changeUserAuthorizations("greg", new Authorizations("X", "Y",
"Z"));
@@ -120,7 +125,7 @@ public class MockConnectorTest {
   
   @Test
   public void testDelete() throws Exception {
-    Connector c = new MockConnector("root");
+    Connector c = new MockConnector("root", new MockInstance());
     c.tableOperations().create("test");
     BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
     
@@ -159,7 +164,7 @@ public class MockConnectorTest {
   
   @Test
   public void testDeletewithBatchDeleter() throws Exception {
-    Connector c = new MockConnector("root");
+    Connector c = new MockConnector("root", new MockInstance());
     
     // make sure we are using a clean table
     if (c.tableOperations().exists("test"))
@@ -230,7 +235,7 @@ public class MockConnectorTest {
   @Test
   public void testCMod() throws Exception {
     // test writing to a table that the is being scanned
-    Connector c = new MockConnector("root");
+    Connector c = new MockConnector("root", new MockInstance());
     c.tableOperations().create("test");
     BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
     
@@ -281,7 +286,7 @@ public class MockConnectorTest {
   
   @Test
   public void testMockMultiTableBatchWriter() throws Exception {
-    Connector c = new MockConnector("root");
+    Connector c = new MockConnector("root", new MockInstance());
     c.tableOperations().create("a");
     c.tableOperations().create("b");
     MultiTableBatchWriter bw = c.createMultiTableBatchWriter(new BatchWriterConfig());
@@ -313,7 +318,7 @@ public class MockConnectorTest {
   
   @Test
   public void testUpdate() throws Exception {
-    Connector c = new MockConnector("root");
+    Connector c = new MockConnector("root", new MockInstance());
     c.tableOperations().create("test");
     BatchWriter bw = c.createBatchWriter("test", new BatchWriterConfig());
     
@@ -332,5 +337,14 @@ public class MockConnectorTest {
     assertEquals("9", entry.getValue().toString());
 
   }
+  
+  @Test
+  public void testMockConnectorReturnsCorrectInstance() throws AccumuloException, 
+      AccumuloSecurityException{
+    String name = "an-interesting-instance-name";
+    Instance mockInstance = new MockInstance(name);
+    Assert.assertEquals(mockInstance, mockInstance.getConnector("foo", "bar").getInstance());
+    Assert.assertEquals(name, mockInstance.getConnector("foo","bar").getInstance().getInstanceName());
+  }
 
 }



Mime
View raw message