congrats Icon
New! Tabnine Pro 14-day free trial
Start a free trial
Tabnine Logo
TestContext.create
Code IndexAdd Tabnine to your IDE (free)

How to use
create
method
in
com.vmware.xenon.common.test.TestContext

Best Java code snippets using com.vmware.xenon.common.test.TestContext.create (Showing top 14 results out of 315)

origin: vmware/admiral

public static TestContext testCreate(int count) {
  long expIntervalMicros = TimeUnit.MILLISECONDS.toMicros(
      WAIT_FOR_STAGE_CHANGE_COUNT * WAIT_THREAD_SLEEP_IN_MILLIS);
  return TestContext.create(count, expIntervalMicros);
}
origin: vmware/xenon

/**
 * Creates a test wait context that can be nested and isolated from other wait contexts
 */
public TestContext testCreate(int c) {
  return TestContext.create(c, TimeUnit.SECONDS.toMicros(this.timeoutSeconds));
}
origin: com.vmware.xenon/xenon-common

/**
 * Creates a test wait context that can be nested and isolated from other wait contexts
 */
public TestContext testCreate(int c) {
  return TestContext.create(c, TimeUnit.SECONDS.toMicros(this.timeoutSeconds));
}
origin: com.vmware.xenon/xenon-common

public void testStart(String testName, EnumSet<TestProperty> properties, long c) {
  if (this.isSingleton) {
    throw new IllegalStateException("Use startTest on singleton, shared host instances");
  }
  if (this.context != null) {
    throw new IllegalStateException("A test is already started");
  }
  String negative = properties != null && properties.contains(TestProperty.FORCE_FAILURE)
      ? "(NEGATIVE)"
      : "";
  if (c > 1) {
    log("%sTest %s, iterations %d, started", negative, testName, c);
  }
  this.failure = null;
  this.expectedCompletionCount = c;
  this.testStartMicros = Utils.getSystemNowMicrosUtc();
  this.context = TestContext.create((int) c, TimeUnit.SECONDS.toMicros(this.timeoutSeconds));
}
origin: vmware/xenon

public void testStart(String testName, EnumSet<TestProperty> properties, long c) {
  if (this.isSingleton) {
    throw new IllegalStateException("Use startTest on singleton, shared host instances");
  }
  if (this.context != null) {
    throw new IllegalStateException("A test is already started");
  }
  String negative = properties != null && properties.contains(TestProperty.FORCE_FAILURE)
      ? "(NEGATIVE)"
      : "";
  if (c > 1) {
    log("%sTest %s, iterations %d, started", negative, testName, c);
  }
  this.failure = null;
  this.expectedCompletionCount = c;
  this.testStartMicros = Utils.getSystemNowMicrosUtc();
  this.context = TestContext.create((int) c, TimeUnit.SECONDS.toMicros(this.timeoutSeconds));
}
origin: vmware/admiral

public static void runParallel(ExecutorService es, long timeoutSeconds, int count,
    RunnableWithThrowable runnable) {
  TestContext tc = TestContext.create(count, TimeUnit.SECONDS.toMicros(timeoutSeconds));
  for (int i = 0; i < count; i++) {
    int i2 = i;
    es.submit(() -> {
      try {
        runnable.run(i2);
        tc.complete();
      } catch (Throwable e) {
        tc.fail(e);
      }
    });
  }
  tc.await();
}
origin: com.vmware.xenon/xenon-common

private void doTestWithLoad() throws Throwable {
  TestContext ctx = TestContext.create(1, TimeUnit.MINUTES.toMicros(1));
  CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
    this.doParallelTest(PARALLELISM, true);
  });
  future.whenComplete(ctx.getCompletionDeferred());
  List<DeferredResult<String>> deferredResults = new ArrayList<>();
  while (!future.isDone() && deferredResults.size() < 500) {
    ExampleServiceState state = new ExampleServiceState();
    state.name = "test";
    Operation postOp = Operation.createPost(this.host, ExampleService.FACTORY_LINK)
        .setBody(state).forceRemote();
    deferredResults.add(this.host.sendWithDeferredResult(postOp, ExampleServiceState.class)
        .thenApply(s -> s.documentSelfLink));
    Thread.sleep(3); // Slowdown
    if (Math.random() < 1 / 100.0) {
      System.gc();
    }
  }
  this.host.log("Requests sent: %d", deferredResults.size());
  ctx.await();
  ctx = TestContext.create(1, TimeUnit.MINUTES.toMicros(1));
  DeferredResult.allOf(deferredResults)
      .whenComplete(ctx.getCompletionDeferred());
  ctx.await();
  System.gc();
}
origin: vmware/xenon

private void doParallelTest(int parallelism, boolean isRemote) {
  TestContext ctx = TestContext.create(parallelism, TimeUnit.MINUTES.toMicros(1));
  List<ServerSentEvent> events = new ArrayList<>();
  for (int i = 0; i < parallelism; ++i) {
    Operation get = Operation.createGet(this.host, EventStreamService.SELF_LINK)
        .setServerSentEventHandler(event -> {
          synchronized (events) {
            events.add(event);
          }
        })
        .setCompletion(ctx.getCompletion());
    if (isRemote) {
      get.forceRemote();
    }
    this.host.send(get);
  }
  ctx.await();
  assertEquals(EVENTS.size() * parallelism, events.size());
}
origin: vmware/xenon

private void doTestWithLoad() throws Throwable {
  TestContext ctx = TestContext.create(1, TimeUnit.MINUTES.toMicros(1));
  CompletableFuture<Void> future = CompletableFuture.runAsync(() -> {
    this.doParallelTest(PARALLELISM, true);
  });
  future.whenComplete(ctx.getCompletionDeferred());
  List<DeferredResult<String>> deferredResults = new ArrayList<>();
  while (!future.isDone() && deferredResults.size() < 500) {
    ExampleServiceState state = new ExampleServiceState();
    state.name = "test";
    Operation postOp = Operation.createPost(this.host, ExampleService.FACTORY_LINK)
        .setBody(state).forceRemote();
    deferredResults.add(this.host.sendWithDeferredResult(postOp, ExampleServiceState.class)
        .thenApply(s -> s.documentSelfLink));
    Thread.sleep(3); // Slowdown
    if (Math.random() < 1 / 100.0) {
      System.gc();
    }
  }
  this.host.log("Requests sent: %d", deferredResults.size());
  ctx.await();
  ctx = TestContext.create(1, TimeUnit.MINUTES.toMicros(1));
  DeferredResult.allOf(deferredResults)
      .whenComplete(ctx.getCompletionDeferred());
  ctx.await();
  System.gc();
}
origin: com.vmware.xenon/xenon-common

private void doParallelTest(int parallelism, boolean isRemote) {
  TestContext ctx = TestContext.create(parallelism, TimeUnit.MINUTES.toMicros(1));
  List<ServerSentEvent> events = new ArrayList<>();
  for (int i = 0; i < parallelism; ++i) {
    Operation get = Operation.createGet(this.host, EventStreamService.SELF_LINK)
        .setServerSentEventHandler(event -> {
          synchronized (events) {
            events.add(event);
          }
        })
        .setCompletion(ctx.getCompletion());
    if (isRemote) {
      get.forceRemote();
    }
    this.host.send(get);
  }
  ctx.await();
  assertEquals(EVENTS.size() * parallelism, events.size());
}
origin: vmware/xenon

private void doSimpleTest(boolean isRemote) {
  TestContext ctx = TestContext.create(1, TimeUnit.MINUTES.toMicros(1));
  List<ServerSentEvent> events = new ArrayList<>();
  List<Long> timesReceived = new ArrayList<>();
  Operation get = Operation.createGet(this.host, EventStreamService.SELF_LINK)
      .setHeadersReceivedHandler(op -> {
        assertEquals(Operation.MEDIA_TYPE_TEXT_EVENT_STREAM,
            op.getContentType());
        assertEquals(0, events.size());
      })
      .setServerSentEventHandler(event -> {
        timesReceived.add(System.currentTimeMillis());
        events.add(event);
      })
      .setCompletion(ctx.getCompletion());
  if (isRemote) {
    get.forceRemote();
  }
  this.host.send(get);
  ctx.await();
  assertEquals(EVENTS, events);
  double averageDelay = IntStream.range(1, timesReceived.size())
      .mapToLong(i -> timesReceived.get(i) - timesReceived.get(i - 1))
      .average().getAsDouble();
  Assert.assertTrue(averageDelay >= EVENT_EMIT_PERIOD_MS / 2.0);
}
origin: com.vmware.xenon/xenon-common

private void doSimpleTest(boolean isRemote) {
  TestContext ctx = TestContext.create(1, TimeUnit.MINUTES.toMicros(1));
  List<ServerSentEvent> events = new ArrayList<>();
  List<Long> timesReceived = new ArrayList<>();
  Operation get = Operation.createGet(this.host, EventStreamService.SELF_LINK)
      .setHeadersReceivedHandler(op -> {
        assertEquals(Operation.MEDIA_TYPE_TEXT_EVENT_STREAM,
            op.getContentType());
        assertEquals(0, events.size());
      })
      .setServerSentEventHandler(event -> {
        timesReceived.add(System.currentTimeMillis());
        events.add(event);
      })
      .setCompletion(ctx.getCompletion());
  if (isRemote) {
    get.forceRemote();
  }
  this.host.send(get);
  ctx.await();
  assertEquals(EVENTS, events);
  double averageDelay = IntStream.range(1, timesReceived.size())
      .mapToLong(i -> timesReceived.get(i) - timesReceived.get(i - 1))
      .average().getAsDouble();
  Assert.assertTrue(averageDelay >= EVENT_EMIT_PERIOD_MS / 2.0);
}
origin: vmware/xenon

public static String create(ServiceHost h, ServiceOption... extraOptions)
    throws Throwable {
  // create an on demand load factory and services
  TestContext ctx = TestContext.create(1, h.getOperationTimeoutMicros());
  OnDemandLoadFactoryService s = new OnDemandLoadFactoryService();
  EnumSet<ServiceOption> childOptions = EnumSet.of(ServiceOption.PERSISTENCE,
      ServiceOption.REPLICATION, ServiceOption.OWNER_SELECTION);
  if (extraOptions != null) {
    for (ServiceOption eo : extraOptions) {
      childOptions.add(eo);
    }
  }
  s.setChildServiceCaps(childOptions);
  Operation factoryPost = Operation.createPost(
      UriUtils.buildUri(h, s.getClass()))
      .setCompletion(ctx.getCompletion());
  h.startService(factoryPost, s);
  ctx.await();
  String factoryLink = s.getSelfLink();
  h.log(Level.INFO, "Started on demand load factory at %s", factoryLink);
  return factoryLink;
}
origin: com.vmware.xenon/xenon-common

public static String create(ServiceHost h, ServiceOption... extraOptions)
    throws Throwable {
  // create an on demand load factory and services
  TestContext ctx = TestContext.create(1, h.getOperationTimeoutMicros());
  OnDemandLoadFactoryService s = new OnDemandLoadFactoryService();
  EnumSet<ServiceOption> childOptions = EnumSet.of(ServiceOption.PERSISTENCE,
      ServiceOption.REPLICATION, ServiceOption.OWNER_SELECTION);
  if (extraOptions != null) {
    for (ServiceOption eo : extraOptions) {
      childOptions.add(eo);
    }
  }
  s.setChildServiceCaps(childOptions);
  Operation factoryPost = Operation.createPost(
      UriUtils.buildUri(h, s.getClass()))
      .setCompletion(ctx.getCompletion());
  h.startService(factoryPost, s);
  ctx.await();
  String factoryLink = s.getSelfLink();
  h.log(Level.INFO, "Started on demand load factory at %s", factoryLink);
  return factoryLink;
}
com.vmware.xenon.common.testTestContextcreate

Javadoc

Consider using #TestContext(int,Duration)This method exists for backward compatibility, and may be deprecated/deleted in future.

Popular methods of TestContext

  • await
  • fail
  • completeIteration
    Consider using #complete(). This method exists for backward compatibility, and may be deprecated/del
  • failIteration
    Consider using #fail(Throwable). This method exists for backward compatibility, and may be deprecate
  • <init>
  • complete
  • getCompletion
  • getExpectedFailureCompletion
  • getCompletionDeferred
  • logAfter
  • logBefore
  • setCheckInterval
  • logBefore,
  • setCheckInterval,
  • setTestName,
  • waitFor

Popular in Java

  • Making http post requests using okhttp
  • getContentResolver (Context)
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • notifyDataSetChanged (ArrayAdapter)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • Kernel (java.awt.image)
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • BoxLayout (javax.swing)
  • JButton (javax.swing)
  • Join (org.hibernate.mapping)
  • Top 17 Free Sublime Text Plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now