Skip to content

Commit

Permalink
Improved linux behaviours (#548)
Browse files Browse the repository at this point in the history
* improved file read failure mode

* guarded file browse

* test fix, groupid consolidation

* JRE-provoked test fix, automated refactor
  • Loading branch information
therealryan authored Sep 22, 2023
1 parent dde5f41 commit e9344c1
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 34 deletions.
14 changes: 7 additions & 7 deletions aggregator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>builder</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>message-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>message-text</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down Expand Up @@ -66,7 +66,7 @@
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>model</artifactId>
<version>${project.version}</version>
</dependency>
Expand All @@ -84,13 +84,13 @@
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>validation-junit5</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>coppice</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down Expand Up @@ -120,7 +120,7 @@
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>assert-junit5</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,7 @@ void asInt() {
// invalid value, no default
Option noDefault = new Builder().property( "tstopt" );
noDefault.set( "not an int" );
assertEquals( "null",
assertThrows( NumberFormatException.class, () -> noDefault.asInt() )
.getMessage() );
assertThrows( NumberFormatException.class, () -> noDefault.asInt() );

// invalid value, invalid default
Option badDefault = new Builder().property( "tstopt" ).defaultValue( "not an int either" );
Expand Down
14 changes: 7 additions & 7 deletions bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,19 @@
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>builder</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>message-core</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>message-text</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down Expand Up @@ -68,7 +68,7 @@
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>model</artifactId>
<version>${project.version}</version>
</dependency>
Expand All @@ -86,13 +86,13 @@
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>validation-junit5</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>coppice</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down Expand Up @@ -122,7 +122,7 @@
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>assert-junit5</artifactId>
<version>${project.version}</version>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion doc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dependencies>
<dependency>
<!-- controls flow artifact versions -->
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>bom</artifactId>
<version>${project.version}</version>
<type>pom</type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand All @@ -22,7 +21,6 @@
import java.util.stream.Stream;

import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.TestFactory;

/**
Expand Down Expand Up @@ -130,23 +128,18 @@ private Snippet extract( Path file, String name ) {
if( ex == null ) {

String content = new String( Files.readAllBytes( file ), UTF_8 );
Iterator<String> lines = Arrays.asList( content.split( "\n", -1 ) ).iterator();
Map<String, Snippet> extant = new HashMap<>();
int lineNumber = 0;

while( lines.hasNext() ) {
for( String line : Arrays.asList( content.split( "\n", -1 ) ) ) {
lineNumber++;
String line = lines.next();

Delimiter sd = delimiter( file );
Matcher start = sd.start.matcher( line.trim() );
Matcher end = sd.end.matcher( line.trim() );
if( start.matches() ) {

extant.put( start.group( 1 ), new Snippet( file, lineNumber + 1 ) );
}
else if( end.matches() ) {

excerpts.put( file + ":" + end.group( 1 ),
extant.remove( end.group( 1 ) ) );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import static com.mastercard.test.flow.example.app.model.ExampleSystem.Unpredictables.RNG;

import java.awt.Desktop;
import java.awt.Desktop.Action;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
Expand Down Expand Up @@ -105,7 +106,7 @@ public static void stopApp() throws Exception {

// open the browser
URI uri = new URI( "http://localhost:" + service.port() );
if( Desktop.isDesktopSupported() ) {
if( Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported( Action.BROWSE ) ) {
System.out.println( "Opening browser to " + uri );
Desktop.getDesktop().browse( uri );
}
Expand Down
4 changes: 2 additions & 2 deletions message/message-http/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>message-json</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.mastercard.test.flow</groupId>
<groupId>${project.groupId}</groupId>
<artifactId>message-text</artifactId>
<version>${project.version}</version>
<scope>test</scope>
Expand Down
2 changes: 1 addition & 1 deletion message/message-web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ if( assrt.expected().request() instanceof WebSequence
response = results.process( driver );
}
```
[Snippet context](../../example/app-itest/src/test/java/com/mastercard/test/flow/example/app/itest/IntegrationTest.java#L154-L165,154-165)
[Snippet context](../../example/app-itest/src/test/java/com/mastercard/test/flow/example/app/itest/IntegrationTest.java#L155-L166,155-166)

<!-- snippet end -->

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ private static <T> T extract( URI uri, Class<T> type ) {
return Template.extract( file, type );
}
catch( @SuppressWarnings("unused") FileNotFoundException fnfe ) {
if( fnfe.getMessage().contains( "Permission denied" ) ) {
// on linux platforms missing read permission results in a
// FileNotFoundException.
// Our semantics return null if there is no data, so this would be a confusing
// debug session: the file is *definitely* there, but Flow is claiming
// otherwise by returning null!
// Hence we're reduced to looking at the exception message. This is obviously
// really fragile, but I don't see a better option
throw new IllegalStateException( "Failed to read " + uri, fnfe );
}
return null;
}
catch( IOException | UncheckedIOException e ) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.util.Arrays;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;
Expand Down Expand Up @@ -103,7 +102,7 @@ void noReport() {
}

/**
* What happens when we can't read the index /
* What happens when we can't read the index
*
* @throws Exception unexpected oopsy
*/
Expand Down Expand Up @@ -134,8 +133,6 @@ void badReadWindows() throws Exception {
*/
@Test
@EnabledOnOs(OS.LINUX)
@Disabled("TODO: get this working on linux, "
+ "becuase harrassing the github build agents is a painful iteration")
void badReadLinux() throws Exception {
Path dir = Paths.get( "target", "ReaderTest", "badReadLinux" );
WriterTest.writeReport( dir );
Expand Down

0 comments on commit e9344c1

Please sign in to comment.