Skip to content
This repository has been archived by the owner on Feb 9, 2021. It is now read-only.

Commit

Permalink
BZ-1287511: avoid workbench hard restart due errors like missing tree
Browse files Browse the repository at this point in the history
or something like that might happen during diff notification.
  • Loading branch information
porcelli authored and csadilek committed Dec 7, 2015
1 parent 2897ef8 commit de5fa01
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 15 deletions.
Expand Up @@ -1980,14 +1980,17 @@ private void notifyAllDiffs() {
for ( Map.Entry<JGitFileSystem, Map<String, NotificationModel>> jGitFileSystemMapEntry : oldHeadsOfPendingDiffs.entrySet() ) {
for ( Map.Entry<String, NotificationModel> branchNameNotificationModelEntry : jGitFileSystemMapEntry.getValue().entrySet() ) {
final ObjectId newHead = JGitUtil.getTreeRefObjectId( jGitFileSystemMapEntry.getKey().gitRepo().getRepository(), branchNameNotificationModelEntry.getKey() );

notifyDiffs( jGitFileSystemMapEntry.getKey(),
branchNameNotificationModelEntry.getKey(),
branchNameNotificationModelEntry.getValue().getSessionId(),
branchNameNotificationModelEntry.getValue().getUserName(),
branchNameNotificationModelEntry.getValue().getMessage(),
branchNameNotificationModelEntry.getValue().getOriginalHead(),
newHead );
try {
notifyDiffs( jGitFileSystemMapEntry.getKey(),
branchNameNotificationModelEntry.getKey(),
branchNameNotificationModelEntry.getValue().getSessionId(),
branchNameNotificationModelEntry.getValue().getUserName(),
branchNameNotificationModelEntry.getValue().getMessage(),
branchNameNotificationModelEntry.getValue().getOriginalHead(),
newHead );
} catch ( final Exception ex ) {
LOG.error( String.format( "Couldn't produce diff notification for repository `%s` branch `%s`.", jGitFileSystemMapEntry.getKey().toString(), branchNameNotificationModelEntry.getKey() ), ex );
}
}
}

Expand All @@ -2003,13 +2006,13 @@ private void notifyAllDiffs() {
}
}

private void notifyDiffs( final JGitFileSystem fs,
final String _tree,
final String sessionId,
final String userName,
final String message,
final ObjectId oldHead,
final ObjectId newHead ) {
void notifyDiffs( final JGitFileSystem fs,
final String _tree,
final String sessionId,
final String userName,
final String message,
final ObjectId oldHead,
final ObjectId newHead ) {

final String tree;
if ( _tree.startsWith( "refs/" ) ) {
Expand Down
Expand Up @@ -59,6 +59,7 @@
import org.uberfire.java.nio.fs.jgit.util.JGitUtil.*;

import static org.fest.assertions.api.Assertions.*;
import static org.mockito.Mockito.*;
import static org.uberfire.java.nio.file.StandardDeleteOption.*;
import static org.uberfire.java.nio.fs.jgit.util.JGitUtil.*;

Expand Down Expand Up @@ -1354,6 +1355,42 @@ public void checkProperAmend() throws Exception {
assertThat( attrs.readAttributes().history().records().size() ).isEqualTo( 5 );
}

@Test
public void checkBatchError() throws Exception {
final URI newRepo = URI.create( "git://outstream-test-repo" );

final FileSystem fs = provider.newFileSystem( newRepo, new HashMap<String, Object>() {{
put( JGitFileSystemProvider.GIT_ENV_KEY_INIT, "true" );
}} );

provider = spy( provider );

doThrow( new RuntimeException() ).
when( provider ).
notifyDiffs( any( JGitFileSystem.class ),
any( String.class ),
any( String.class ),
any( String.class ),
any( String.class ),
any( ObjectId.class ),
any( ObjectId.class ) );

assertThat( fs ).isNotNull();

final Path path = provider.getPath( URI.create( "git://user_branch@outstream-test-repo/some/path/myfile.txt" ) );
provider.setAttribute( path, FileSystemState.FILE_SYSTEM_STATE_ATTR, FileSystemState.BATCH );
final OutputStream outStream = provider.newOutputStream( path );
assertThat( outStream ).isNotNull();
outStream.write( ( "my cool content" ).getBytes() );
outStream.close();

try {
provider.setAttribute( path, FileSystemState.FILE_SYSTEM_STATE_ATTR, FileSystemState.NORMAL );
} catch ( Exception ex ) {
fail( "Batch can't fail!", ex );
}
}

private static interface MyAttrs extends BasicFileAttributes {

}
Expand Down

0 comments on commit de5fa01

Please sign in to comment.