Skip to content

Commit

Permalink
Better name for the TokenCreator method.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvest committed May 22, 2018
1 parent 215a4aa commit 8b29424
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 9 deletions.
Expand Up @@ -100,7 +100,7 @@ private synchronized int createToken( String name ) throws KernelException
return id;
}

id = tokenCreator.getOrCreate( name );
id = tokenCreator.createToken( name );
try
{
tokenCache.put( tokenFactory.newToken( name, id ) );
Expand Down
Expand Up @@ -49,7 +49,7 @@ abstract class IsolatedTransactionTokenCreator implements TokenCreator
}

@Override
public synchronized int getOrCreate( String name ) throws KernelException
public synchronized int createToken( String name ) throws KernelException
{
Kernel kernel = kernelSupplier.get();
try ( Session session = kernel.beginSession( LoginContext.AUTH_DISABLED ) )
Expand Down
Expand Up @@ -28,7 +28,7 @@ public class ReadOnlyTokenCreator
implements TokenCreator
{
@Override
public int getOrCreate( String name ) throws ReadOnlyDbException
public int createToken( String name ) throws ReadOnlyDbException
{
throw new ReadOnlyDbException();
}
Expand Down
Expand Up @@ -23,5 +23,13 @@

public interface TokenCreator
{
int getOrCreate( String name ) throws KernelException;
/**
* Create a token by the given name and return the newly allocated id for this token.
*
* It is assumed that the token name is not already being used.
* @param name The token name to allocate.
* @return The id of the allocated token name.
* @throws KernelException If the inner transaction used to allocate the token encountered a problem.
*/
int createToken( String name ) throws KernelException;
}
Expand Up @@ -42,7 +42,7 @@ protected AbstractTokenCreator( Master master, RequestContextFactory requestCont
}

@Override
public final int getOrCreate( String name )
public final int createToken( String name )
{
try ( Response<Integer> response = create( master, requestContextFactory.newRequestContext(), name ) )
{
Expand Down
Expand Up @@ -76,7 +76,7 @@ public void shouldCreateALabelOnMasterAndApplyItLocally()
int responseValue = response.response();

// WHEN
int result = creator.getOrCreate( label );
int result = creator.createToken( label );

// THEN
assertEquals( responseValue, result );
Expand All @@ -93,7 +93,7 @@ public void shouldThrowIfCreateThrowsAnException()
try
{
// WHEN
throwingCreator.getOrCreate( "A" );
throwingCreator.createToken( "A" );
fail( "Should have thrown" );
}
catch ( Exception e )
Expand Down
Expand Up @@ -124,13 +124,13 @@ public SlaveTokenCreatorTest( String name, SlaveTokenCreatorFixture fixture )
public void mustTranslateComExceptionsToTransientTransactionFailures()
{
when( fixture.callMasterMethod( master, requestContext, name ) ).thenThrow( new ComException() );
tokenCreator.getOrCreate( name );
tokenCreator.createToken( name );
}

@Test
public void mustReturnIdentifierFromMaster()
{
when( fixture.callMasterMethod( master, requestContext, name ) ).thenReturn( new IntegerResponse( 13 ) );
assertThat( tokenCreator.getOrCreate( name ), is( 13 ) );
assertThat( tokenCreator.createToken( name ), is( 13 ) );
}
}

0 comments on commit 8b29424

Please sign in to comment.