Tabnine Logo
LimiterServerResource.getSync
Code IndexAdd Tabnine to your IDE (free)

How to use
getSync
method
in
org.apache.gobblin.restli.throttling.LimiterServerResource

Best Java code snippets using org.apache.gobblin.restli.throttling.LimiterServerResource.getSync (Showing top 5 results out of 315)

origin: apache/incubator-gobblin

 @Override
 public void run() {
  try {
   while (true) {
    RequestAndCallback requestAndCallback = MockRequester.this.requestAndCallbackQueue.take();
    long nanoTime = System.nanoTime();
    long delayNanos = requestAndCallback.getProcessAfterNanos() - nanoTime;
    if (delayNanos > 0) {
     Thread.sleep(TimeUnit.NANOSECONDS.toMillis(delayNanos));
    }
    try {
     PermitAllocation allocation =
       MockRequester.this.limiterServer.getSync(new ComplexResourceKey<>(requestAndCallback.getRequest(), new EmptyRecord()));
     Response<PermitAllocation> response = Mockito.mock(Response.class);
     Mockito.when(response.getEntity()).thenReturn(allocation);
     requestAndCallback.getCallback().onSuccess(response);
    } catch (RestLiServiceException rexc) {
     RestLiResponseException returnException = Mockito.mock(RestLiResponseException.class);
     Mockito.when(returnException.getStatus()).thenReturn(rexc.getStatus().getCode());
     requestAndCallback.getCallback().onError(returnException);
    }
   }
  } catch (Throwable t) {
   log.error("Error", t);
   throw new RuntimeException(t);
  }
 }
}
origin: apache/incubator-gobblin

@Test
public void testMetrics() throws Exception {
 ThrottlingGuiceServletConfig guiceServletConfig = new ThrottlingGuiceServletConfig();
 guiceServletConfig.initialize(ConfigFactory.empty());
 Injector injector = guiceServletConfig.getInjector();
 LimiterServerResource limiterServer = injector.getInstance(LimiterServerResource.class);
 PermitRequest request = new PermitRequest();
 request.setPermits(10);
 request.setResource("myResource");
 limiterServer.getSync(new ComplexResourceKey<>(request, new EmptyRecord()));
 limiterServer.getSync(new ComplexResourceKey<>(request, new EmptyRecord()));
 limiterServer.getSync(new ComplexResourceKey<>(request, new EmptyRecord()));
 MetricContext metricContext = limiterServer.metricContext;
 Timer timer = metricContext.timer(LimiterServerResource.REQUEST_TIMER_NAME);
 Assert.assertEquals(timer.getCount(), 3);
}
origin: apache/incubator-gobblin

@Test
public void test() {
 ThrottlingGuiceServletConfig guiceServletConfig = new ThrottlingGuiceServletConfig();
 guiceServletConfig.initialize(ConfigFactory.empty());
 Injector injector = guiceServletConfig.getInjector();
 LimiterServerResource limiterServer = injector.getInstance(LimiterServerResource.class);
 PermitRequest request = new PermitRequest();
 request.setPermits(10);
 request.setResource("myResource");
 PermitAllocation allocation = limiterServer.getSync(new ComplexResourceKey<>(request, new EmptyRecord()));
 Assert.assertTrue(allocation.getPermits() >= 10);
}
origin: apache/incubator-gobblin

private PermitAllocation sendRequestToServer(ThrottlingGuiceServletConfig guiceServletConfig, long permits) {
 return guiceServletConfig.getLimiterResource()
   .getSync(new ComplexResourceKey<>(createPermitRequest(10), new EmptyRecord()));
}
origin: apache/incubator-gobblin

res3request.setResource("res3");
Assert.assertEquals(limiterServer.getSync(new ComplexResourceKey<>(res1request, new EmptyRecord())).getPermits(), new Long(20));
Assert.assertEquals(limiterServer.getSync(new ComplexResourceKey<>(res1request, new EmptyRecord())).getPermits(), new Long(20));
Assert.assertEquals(limiterServer.getSync(new ComplexResourceKey<>(res1request, new EmptyRecord())).getPermits(), new Long(20));
Assert.assertEquals(limiterServer.getSync(new ComplexResourceKey<>(res1request, new EmptyRecord())).getPermits(), new Long(20));
Assert.assertEquals(limiterServer.getSync(new ComplexResourceKey<>(res1request, new EmptyRecord())).getPermits(), new Long(20));
 limiterServer.getSync(new ComplexResourceKey<>(res1request, new EmptyRecord())).getPermits();
 Assert.fail();
} catch (RestLiServiceException exc) {
Assert.assertEquals(limiterServer.getSync(new ComplexResourceKey<>(res2request, new EmptyRecord())).getPermits(), new Long(20));
Assert.assertEquals(limiterServer.getSync(new ComplexResourceKey<>(res2request, new EmptyRecord())).getPermits(), new Long(20));
 limiterServer.getSync(new ComplexResourceKey<>(res2request, new EmptyRecord())).getPermits();
 Assert.fail();
} catch (RestLiServiceException exc) {
Assert.assertTrue(limiterServer.getSync(new ComplexResourceKey<>(res3request, new EmptyRecord())).getPermits() >= res3request.getPermits());
org.apache.gobblin.restli.throttlingLimiterServerResourcegetSync

Javadoc

Request permits from the limiter server. The returned PermitAllocation specifies the number of permits that the client can use.

Popular methods of LimiterServerResource

  • get
    Request permits from the limiter server. The returned PermitAllocation specifies the number of permi

Popular in Java

  • Making http requests using okhttp
  • scheduleAtFixedRate (Timer)
  • onCreateOptionsMenu (Activity)
  • getSupportFragmentManager (FragmentActivity)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • BigDecimal (java.math)
    An immutable arbitrary-precision signed decimal.A value is represented by an arbitrary-precision "un
  • Time (java.sql)
    Java representation of an SQL TIME value. Provides utilities to format and parse the time's represen
  • DateFormat (java.text)
    Formats or parses dates and times.This class provides factories for obtaining instances configured f
  • Enumeration (java.util)
    A legacy iteration interface.New code should use Iterator instead. Iterator replaces the enumeration
  • JComboBox (javax.swing)
  • From CI to AI: The AI layer in your organization
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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