aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dmclaugh...@apache.org
Subject [1/4] aurora git commit: Revert removal of twitter/commons/zk based leadership code
Date Thu, 01 Dec 2016 17:02:30 GMT
Repository: aurora
Updated Branches:
  refs/heads/master 8bcad84dc -> 16e4651d5


http://git-wip-us.apache.org/repos/asf/aurora/blob/16e4651d/src/test/java/org/apache/aurora/scheduler/discovery/JsonCodecTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/discovery/JsonCodecTest.java b/src/test/java/org/apache/aurora/scheduler/discovery/JsonCodecTest.java
deleted file mode 100644
index b88ba37..0000000
--- a/src/test/java/org/apache/aurora/scheduler/discovery/JsonCodecTest.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/**
- * Licensed 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.aurora.scheduler.discovery;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-
-import com.google.common.base.Charsets;
-import com.google.common.collect.ImmutableMap;
-import com.google.gson.Gson;
-import com.google.gson.JsonIOException;
-
-import org.apache.aurora.common.thrift.Endpoint;
-import org.apache.aurora.common.thrift.ServiceInstance;
-import org.apache.aurora.common.thrift.Status;
-import org.easymock.EasyMock;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.powermock.api.easymock.PowerMock;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(Gson.class)
-public class JsonCodecTest {
-
-  private static byte[] serializeServiceInstance(ServiceInstance serviceInstance)
-      throws IOException {
-
-    ByteArrayOutputStream output = new ByteArrayOutputStream();
-    JsonCodec.INSTANCE.serialize(serviceInstance, output);
-    return output.toByteArray();
-  }
-
-  private static ServiceInstance deserializeServiceInstance(byte[] data) throws IOException
{
-    return JsonCodec.INSTANCE.deserialize(new ByteArrayInputStream(data));
-  }
-
-  @Test
-  public void testJsonCodecRoundtrip() throws Exception {
-    ServiceInstance instance1 = new ServiceInstance(
-        new Endpoint("foo", 1000),
-        ImmutableMap.of("http", new Endpoint("foo", 8080)),
-        Status.ALIVE)
-        .setShard(0);
-    byte[] data = serializeServiceInstance(instance1);
-    assertTrue(deserializeServiceInstance(data).getServiceEndpoint().isSetPort());
-    assertTrue(deserializeServiceInstance(data).isSetShard());
-
-    ServiceInstance instance2 = new ServiceInstance(
-        new Endpoint("foo", 1000),
-        ImmutableMap.of("http-admin1", new Endpoint("foo", 8080)),
-        Status.ALIVE);
-    data = serializeServiceInstance(instance2);
-    assertTrue(deserializeServiceInstance(data).getServiceEndpoint().isSetPort());
-    assertFalse(deserializeServiceInstance(data).isSetShard());
-
-    ServiceInstance instance3 = new ServiceInstance(
-        new Endpoint("foo", 1000),
-        ImmutableMap.of(),
-        Status.ALIVE);
-    data = serializeServiceInstance(instance3);
-    assertTrue(deserializeServiceInstance(data).getServiceEndpoint().isSetPort());
-    assertFalse(deserializeServiceInstance(data).isSetShard());
-  }
-
-  @Test
-  public void testJsonCompatibility() throws IOException {
-    ServiceInstance instance = new ServiceInstance(
-        new Endpoint("foo", 1000),
-        ImmutableMap.of("http", new Endpoint("foo", 8080)),
-        Status.ALIVE).setShard(42);
-
-    ByteArrayOutputStream results = new ByteArrayOutputStream();
-    JsonCodec.INSTANCE.serialize(instance, results);
-    assertEquals(
-        "{\"serviceEndpoint\":{\"host\":\"foo\",\"port\":1000},"
-            + "\"additionalEndpoints\":{\"http\":{\"host\":\"foo\",\"port\":8080}},"
-            + "\"status\":\"ALIVE\","
-            + "\"shard\":42}",
-        results.toString(Charsets.UTF_8.name()));
-  }
-
-  @Test
-  public void testInvalidSerialize() {
-    // Gson is final so we need to call on PowerMock here.
-    Gson gson = PowerMock.createMock(Gson.class);
-    gson.toJson(EasyMock.isA(Object.class), EasyMock.isA(Appendable.class));
-    EasyMock.expectLastCall().andThrow(new JsonIOException("error"));
-    PowerMock.replay(gson);
-
-    ServiceInstance instance =
-        new ServiceInstance(new Endpoint("foo", 1000), ImmutableMap.of(), Status.ALIVE);
-
-    try {
-      new JsonCodec(gson).serialize(instance, new ByteArrayOutputStream());
-      fail();
-    } catch (IOException e) {
-      // Expected.
-    }
-
-    PowerMock.verify(gson);
-  }
-
-  @Test
-  public void testDeserializeMinimal() throws IOException {
-    String minimal = "{\"serviceEndpoint\":{\"host\":\"foo\",\"port\":1000},\"status\":\"ALIVE\"}";
-    ByteArrayInputStream source = new ByteArrayInputStream(minimal.getBytes(Charsets.UTF_8));
-    ServiceInstance actual = JsonCodec.INSTANCE.deserialize(source);
-    ServiceInstance expected =
-        new ServiceInstance(new Endpoint("foo", 1000), ImmutableMap.of(), Status.ALIVE);
-    assertEquals(expected, actual);
-  }
-
-  @Test
-  public void testInvalidDeserialize() {
-    // Not JSON.
-    assertInvalidDeserialize(new byte[] {0xC, 0xA, 0xF, 0xE});
-
-    // No JSON object.
-    assertInvalidDeserialize("");
-    assertInvalidDeserialize("[]");
-
-    // Missing required fields.
-    assertInvalidDeserialize("{}");
-    assertInvalidDeserialize("{\"serviceEndpoint\":{\"host\":\"foo\",\"port\":1000}}");
-    assertInvalidDeserialize("{\"status\":\"ALIVE\"}");
-  }
-
-  private void assertInvalidDeserialize(String data) {
-    assertInvalidDeserialize(data.getBytes(Charsets.UTF_8));
-  }
-
-  private void assertInvalidDeserialize(byte[] data) {
-    try {
-      JsonCodec.INSTANCE.deserialize(new ByteArrayInputStream(data));
-      fail();
-    } catch (IOException e) {
-      // Expected.
-    }
-  }
-}

http://git-wip-us.apache.org/repos/asf/aurora/blob/16e4651d/src/test/java/org/apache/aurora/scheduler/discovery/ZooKeeperConfigTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/discovery/ZooKeeperConfigTest.java
b/src/test/java/org/apache/aurora/scheduler/discovery/ZooKeeperConfigTest.java
index 4d833f2..a065505 100644
--- a/src/test/java/org/apache/aurora/scheduler/discovery/ZooKeeperConfigTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/discovery/ZooKeeperConfigTest.java
@@ -14,12 +14,14 @@
 package org.apache.aurora.scheduler.discovery;
 
 import java.net.InetSocketAddress;
-import java.util.Optional;
 
+import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableList;
 
 import org.apache.aurora.common.quantity.Amount;
 import org.apache.aurora.common.quantity.Time;
+import org.apache.aurora.common.zookeeper.Credentials;
+import org.apache.aurora.common.zookeeper.ZooKeeperUtils;
 import org.junit.Test;
 
 import static org.junit.Assert.assertEquals;
@@ -35,22 +37,24 @@ public class ZooKeeperConfigTest {
   @Test(expected = IllegalArgumentException.class)
   public void testEmptyServers() {
     new ZooKeeperConfig(
+        false,
         ImmutableList.of(),
-        Optional.empty(),
+        Optional.absent(),
         false,
         Amount.of(1, Time.DAYS),
-        Optional.empty());
+        Optional.absent());
   }
 
   @Test
   public void testWithCredentials() {
     ZooKeeperConfig config =
         new ZooKeeperConfig(
+            false,
             SERVERS,
-            Optional.empty(),
+            Optional.absent(),
             false,
             Amount.of(1, Time.HOURS),
-            Optional.empty()); // credentials
+            Optional.absent()); // credentials
     assertFalse(config.getCredentials().isPresent());
 
     Credentials joeCreds = Credentials.digestCredentials("Joe", "Schmoe");
@@ -66,8 +70,9 @@ public class ZooKeeperConfigTest {
 
   @Test
   public void testCreateFactory() {
-    ZooKeeperConfig config = ZooKeeperConfig.create(SERVERS);
+    ZooKeeperConfig config = ZooKeeperConfig.create(true, SERVERS);
 
+    assertTrue(config.isUseCurator());
     assertEquals(SERVERS, ImmutableList.copyOf(config.getServers()));
     assertFalse(config.getChrootPath().isPresent());
     assertFalse(config.isInProcess());

http://git-wip-us.apache.org/repos/asf/aurora/blob/16e4651d/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java b/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java
index d9e7374..fb03f25 100644
--- a/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/http/AbstractJettyTest.java
@@ -48,9 +48,9 @@ import org.apache.aurora.scheduler.AppStartup;
 import org.apache.aurora.scheduler.SchedulerServicesModule;
 import org.apache.aurora.scheduler.TierManager;
 import org.apache.aurora.scheduler.app.LifecycleModule;
+import org.apache.aurora.scheduler.app.ServiceGroupMonitor;
 import org.apache.aurora.scheduler.async.AsyncModule;
 import org.apache.aurora.scheduler.cron.CronJobManager;
-import org.apache.aurora.scheduler.discovery.ServiceGroupMonitor;
 import org.apache.aurora.scheduler.http.api.GsonMessageBodyHandler;
 import org.apache.aurora.scheduler.offers.OfferManager;
 import org.apache.aurora.scheduler.scheduling.RescheduleCalculator;
@@ -132,8 +132,9 @@ public abstract class AbstractJettyTest extends EasyMockTest {
             bindMock(Thread.UncaughtExceptionHandler.class);
             bindMock(TaskGroups.TaskGroupBatchWorker.class);
 
-            bind(ServletContextListener.class)
-                .toProvider(() -> makeServletContextListener(injector, getChildServletModule()));
+            bind(ServletContextListener.class).toProvider(() -> {
+              return makeServletContextListener(injector, getChildServletModule());
+            });
           }
         },
         new JettyServerModule(false));
@@ -146,12 +147,12 @@ public abstract class AbstractJettyTest extends EasyMockTest {
     expect(serviceGroupMonitor.get()).andAnswer(schedulers::get).anyTimes();
   }
 
-  void setLeadingScheduler(String host, int port) {
+  protected void setLeadingScheduler(String host, int port) {
     schedulers.set(
         ImmutableSet.of(new ServiceInstance().setServiceEndpoint(new Endpoint(host, port))));
   }
 
-  void unsetLeadingSchduler() {
+  protected void unsetLeadingSchduler() {
     schedulers.set(ImmutableSet.of());
   }
 
@@ -161,7 +162,9 @@ public abstract class AbstractJettyTest extends EasyMockTest {
       ServiceManagerIface service =
           injector.getInstance(Key.get(ServiceManagerIface.class, AppStartup.class));
       service.startAsync().awaitHealthy();
-      addTearDown(() -> service.stopAsync().awaitStopped(5L, TimeUnit.SECONDS));
+      addTearDown(() -> {
+        service.stopAsync().awaitStopped(5L, TimeUnit.SECONDS);
+      });
     } catch (Exception e) {
       throw Throwables.propagate(e);
     }

http://git-wip-us.apache.org/repos/asf/aurora/blob/16e4651d/src/test/java/org/apache/aurora/scheduler/http/LeaderRedirectTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/http/LeaderRedirectTest.java b/src/test/java/org/apache/aurora/scheduler/http/LeaderRedirectTest.java
index a308ba2..a16058f 100644
--- a/src/test/java/org/apache/aurora/scheduler/http/LeaderRedirectTest.java
+++ b/src/test/java/org/apache/aurora/scheduler/http/LeaderRedirectTest.java
@@ -27,8 +27,8 @@ import com.google.common.net.HostAndPort;
 import org.apache.aurora.common.testing.easymock.EasyMockTest;
 import org.apache.aurora.common.thrift.Endpoint;
 import org.apache.aurora.common.thrift.ServiceInstance;
-import org.apache.aurora.scheduler.discovery.ServiceGroupMonitor;
-import org.apache.aurora.scheduler.discovery.ServiceGroupMonitor.MonitorException;
+import org.apache.aurora.scheduler.app.ServiceGroupMonitor;
+import org.apache.aurora.scheduler.app.ServiceGroupMonitor.MonitorException;
 import org.junit.Before;
 import org.junit.Test;
 

http://git-wip-us.apache.org/repos/asf/aurora/blob/16e4651d/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java b/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
index 0119ccb..86861e1 100644
--- a/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
+++ b/src/test/java/org/apache/aurora/scheduler/thrift/ThriftIT.java
@@ -42,12 +42,12 @@ import org.apache.aurora.gen.TaskQuery;
 import org.apache.aurora.scheduler.TierModule;
 import org.apache.aurora.scheduler.app.AppModule;
 import org.apache.aurora.scheduler.app.LifecycleModule;
+import org.apache.aurora.scheduler.app.ServiceGroupMonitor;
 import org.apache.aurora.scheduler.app.local.FakeNonVolatileStorage;
 import org.apache.aurora.scheduler.base.TaskTestUtil;
 import org.apache.aurora.scheduler.configuration.ConfigurationManager.ConfigurationManagerSettings;
 import org.apache.aurora.scheduler.configuration.executor.ExecutorSettings;
 import org.apache.aurora.scheduler.cron.quartz.CronModule;
-import org.apache.aurora.scheduler.discovery.ServiceGroupMonitor;
 import org.apache.aurora.scheduler.mesos.DriverFactory;
 import org.apache.aurora.scheduler.mesos.DriverSettings;
 import org.apache.aurora.scheduler.mesos.TestExecutorSettings;


Mime
View raw message