Skip to content

Instantly share code, notes, and snippets.

class Foo {
private Helper helper = null;
public Helper synchronized getHelper() {
if (helper == null)
helper = new Helper();
return helper;
}
}
class Foo {
private Helper helper = null;
public Helper getHelper() {
if (helper == null)
helper = new Helper();
return helper;
}
}
private Long myNtfSeqNbrCounter = new Long(0);
private Long getNotificationSequenceNumber() {
Long result = null;
synchronized(myNtfSeqNbrCounter) {
result = new Long(myNtfSeqNbrCounter.longValue() + 1);
// ...
myNtfSeqNbrCounter = new Long(result.longValue());
/**
* Manages statistic updates for a Runner in a load test.
*/
public class WebRunnerStatsSender
{
private final Map<String, VariableGroup> resourceToVariableGroup = new HashMap<>();
private final Clock clock;
public WebRunnerStatsSender( Clock clock )
{
/**
* Manages statistic updates for a Runner in a load test.
*/
public class WebRunnerStatsSender
{
private final Map<String, VariableGroup> resourceToVariableGroup = new HashMap<>();
private final Clock clock;
public WebRunnerStatsSender( Clock clock )
{
@Test
public void accessingNonExistentTest_should_fail()
{
asList( "", "/assets", "/live-tabular-stats" )
.forEach( this::assertPathYields404 );
}
private void assertPathYields404( String path )
{
ClientResponse response = R.client().resource( ENDPOINT + "/"+ nonExistentId + path )
@Test
public void startingAndFetch()
{
ClientResponse response = resources.client().resource( ENDPOINT )
.type( MediaType.APPLICATION_JSON )
.header( HttpHeaders.AUTHORIZATION, "Bearer DUMMYTOKEN" )
.post( ClientResponse.class, dummyJson );
assertThat( response.getStatus(), is( 201 ) );
TestRun testRun = resources.client().resource( response.getLocation() )
@minisu
minisu / new.java
Last active August 29, 2015 13:58
@GET
@Path( "/{test}/assets" )
@ApiOperation(value = "Returns all assets in a test run")
@ApiResponses(value = {
@ApiResponse(code = 404, message = "No test with given ID"),
})
public String assets( @Auth User user, @PathParam( "test" ) String testId, @QueryParam( "scenario" ) String scenario )
{
TestRun testRun = testRunStorage.getTestRun( testId, user.getId() )
.orElseThrow( () -> new WebApplicationException( NOT_FOUND );
package com.smartbear.saas.rs.storage;
import com.smartbear.saas.rs.model.TestRun;
import java.util.Optional;
import java.util.Set;
public interface TestRunStorage
{
Optional<TestRun> getTest( String customerId, String testId );
@Before
public void setup() throws ComponentCreationException, IOException
{
ctu = new ComponentTestUtils();
ctu.getDefaultBeanInjectorMocker();
component = ctu.createComponentItem();
ComponentContext contextSpy = spy( component.getContext() );
ctu.mockStatisticsFor( component, contextSpy );