mirror of https://github.com/apache/archiva.git
avoid timing issues with audit logs
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@910400 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
199a251293
commit
0db9498522
|
@ -126,7 +126,9 @@ public class AuditEvent
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
timestamp = createNameFormat().parse( name );
|
int index = name.lastIndexOf( '/' );
|
||||||
|
String ts = index > 0 ? name.substring( 0, index ) : name;
|
||||||
|
timestamp = createNameFormat().parse( ts );
|
||||||
}
|
}
|
||||||
catch ( ParseException e )
|
catch ( ParseException e )
|
||||||
{
|
{
|
||||||
|
@ -211,7 +213,9 @@ public class AuditEvent
|
||||||
|
|
||||||
public String getName()
|
public String getName()
|
||||||
{
|
{
|
||||||
return createNameFormat().format( timestamp );
|
// we add the resource name to the end to avoid clashes at that timestamp
|
||||||
|
// TODO: this is still not robust enough and the content model should be revised
|
||||||
|
return createNameFormat().format( timestamp ) + "/" + resource.substring( resource.lastIndexOf( '/' ) + 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static SimpleDateFormat createNameFormat()
|
private static SimpleDateFormat createNameFormat()
|
||||||
|
|
|
@ -138,16 +138,16 @@ public class AuditManagerTest
|
||||||
return createTestEvent( TEST_REPO_ID, name );
|
return createTestEvent( TEST_REPO_ID, name );
|
||||||
}
|
}
|
||||||
|
|
||||||
private static AuditEvent createTestEvent( String repositoryId, String name )
|
private static AuditEvent createTestEvent( String repositoryId, String t )
|
||||||
throws ParseException
|
throws ParseException
|
||||||
{
|
{
|
||||||
AuditEvent event = new AuditEvent();
|
AuditEvent event = new AuditEvent();
|
||||||
event.setTimestamp( TIMESTAMP_FORMAT.parse( name ) );
|
event.setTimestamp( TIMESTAMP_FORMAT.parse( AUDIT_EVENT_BASE + t ) );
|
||||||
event.setAction( AuditEvent.UPLOAD_FILE );
|
event.setAction( AuditEvent.UPLOAD_FILE );
|
||||||
event.setRemoteIP( TEST_IP_ADDRESS );
|
event.setRemoteIP( TEST_IP_ADDRESS );
|
||||||
event.setRepositoryId( repositoryId );
|
event.setRepositoryId( repositoryId );
|
||||||
event.setUserId( TEST_USER );
|
event.setUserId( TEST_USER );
|
||||||
event.setResource( TEST_RESOURCE_BASE + "/" + name.substring( AUDIT_EVENT_BASE.length() ) );
|
event.setResource( TEST_RESOURCE_BASE + "/" + t );
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,10 +197,11 @@ public class AuditManagerTest
|
||||||
eventNames.put( TEST_REPO_ID_2, new ArrayList<String>() );
|
eventNames.put( TEST_REPO_ID_2, new ArrayList<String>() );
|
||||||
for ( int i = 0; i < numEvents; i++ )
|
for ( int i = 0; i < numEvents; i++ )
|
||||||
{
|
{
|
||||||
String name = AUDIT_EVENT_BASE + MILLIS_FORMAT.format( i );
|
String t = MILLIS_FORMAT.format( i );
|
||||||
|
String name = AUDIT_EVENT_BASE + t + "/" + t;
|
||||||
String repositoryId = i % 2 == 0 ? TEST_REPO_ID : TEST_REPO_ID_2;
|
String repositoryId = i % 2 == 0 ? TEST_REPO_ID : TEST_REPO_ID_2;
|
||||||
eventNames.get( repositoryId ).add( name );
|
eventNames.get( repositoryId ).add( name );
|
||||||
events.add( createTestEvent( repositoryId, name ) );
|
events.add( createTestEvent( repositoryId, t ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
metadataRepositoryControl.expectAndReturn(
|
metadataRepositoryControl.expectAndReturn(
|
||||||
|
|
Loading…
Reference in New Issue