Java Code Examples for org.apache.twill.api.TwillSpecification#Order

The following examples show how to use org.apache.twill.api.TwillSpecification#Order . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TwillSpecificationTest.java    From twill with Apache License 2.0 6 votes vote down vote up
@Test
public void testAnyOrder() {
  TwillSpecification spec =
    TwillSpecification.Builder.with()
      .setName("Testing")
      .withRunnable()
      .add("r1", new DummyRunnable()).noLocalFiles()
      .add("r2", new DummyRunnable()).noLocalFiles()
      .add("r3", new DummyRunnable()).noLocalFiles()
      .anyOrder()
      .build();

  Assert.assertEquals(3, spec.getRunnables().size());
  List<TwillSpecification.Order> orders = spec.getOrders();
  Assert.assertEquals(1, orders.size());
  Assert.assertEquals(ImmutableSet.of("r1", "r2", "r3"), orders.get(0).getNames());
}
 
Example 2
Source File: TwillSpecificationTest.java    From twill with Apache License 2.0 6 votes vote down vote up
@Test
public void testOrder() {
  TwillSpecification spec =
    TwillSpecification.Builder.with()
      .setName("Testing")
      .withRunnable()
      .add("r1", new DummyRunnable()).noLocalFiles()
      .add("r2", new DummyRunnable()).noLocalFiles()
      .add("r3", new DummyRunnable()).noLocalFiles()
      .add("r4", new DummyRunnable()).noLocalFiles()
      .withOrder().begin("r1", "r2").nextWhenStarted("r3")
      .build();

  Assert.assertEquals(4, spec.getRunnables().size());
  List<TwillSpecification.Order> orders = spec.getOrders();
  Assert.assertEquals(3, orders.size());
  Assert.assertEquals(ImmutableSet.of("r1", "r2"), orders.get(0).getNames());
  Assert.assertEquals(ImmutableSet.of("r3"), orders.get(1).getNames());
  Assert.assertEquals(ImmutableSet.of("r4"), orders.get(2).getNames());
}
 
Example 3
Source File: TwillSpecificationCodec.java    From twill with Apache License 2.0 6 votes vote down vote up
@Override
public TwillSpecification deserialize(JsonElement json, Type typeOfT,
                                      JsonDeserializationContext context) throws JsonParseException {
  JsonObject jsonObj = json.getAsJsonObject();

  String name = jsonObj.get("name").getAsString();
  Map<String, RuntimeSpecification> runnables = context.deserialize(
    jsonObj.get("runnables"), new TypeToken<Map<String, RuntimeSpecification>>() { }.getType());
  List<TwillSpecification.Order> orders = context.deserialize(
    jsonObj.get("orders"), new TypeToken<List<TwillSpecification.Order>>() { }.getType());
  List<TwillSpecification.PlacementPolicy> placementPolicies = context.deserialize(
    jsonObj.get("placementPolicies"), new TypeToken<List<TwillSpecification.PlacementPolicy>>() { }.getType());

  JsonElement handler = jsonObj.get("handler");
  EventHandlerSpecification eventHandler = null;
  if (handler != null && !handler.isJsonNull()) {
    eventHandler = context.deserialize(handler, EventHandlerSpecification.class);
  }

  return new DefaultTwillSpecification(name, runnables, orders, placementPolicies, eventHandler);
}
 
Example 4
Source File: TwillSpecificationCodec.java    From twill with Apache License 2.0 5 votes vote down vote up
@Override
public JsonElement serialize(TwillSpecification.Order src, Type typeOfSrc, JsonSerializationContext context) {
  JsonObject json = new JsonObject();
  json.add("names", context.serialize(src.getNames(), new TypeToken<Set<String>>() { }.getType()));
  json.addProperty("type", src.getType().name());
  return json;
}
 
Example 5
Source File: TwillSpecificationCodec.java    From twill with Apache License 2.0 5 votes vote down vote up
@Override
public TwillSpecification.Order deserialize(JsonElement json, Type typeOfT,
                                            JsonDeserializationContext context) throws JsonParseException {
  JsonObject jsonObj = json.getAsJsonObject();

  Set<String> names = context.deserialize(jsonObj.get("names"), new TypeToken<Set<String>>() { }.getType());
  TwillSpecification.Order.Type type = TwillSpecification.Order.Type.valueOf(jsonObj.get("type").getAsString());

  return new DefaultTwillSpecification.DefaultOrder(names, type);
}