protected void verifyCheckpoints( FlowDef flowDef, Pipe[] flowTails ) { verifyNotSourcesSinks( flowDef.getCheckpoints(), flowDef.getSources(), flowDef.getSinks(), "checkpoint" ); for( Tap checkpointTap : flowDef.getCheckpoints().values() ) { Scheme scheme = checkpointTap.getScheme(); if( scheme.getSourceFields().equals( Fields.UNKNOWN ) && scheme.getSinkFields().equals( Fields.ALL ) ) continue; throw new PlannerException( "checkpoint tap scheme must be undeclared, source fields must be UNKNOWN, and sink fields ALL, got: " + scheme.toString() ); } Set<String> names = new HashSet<String>( asList( Pipe.names( flowTails ) ) ); for( String name : flowDef.getCheckpoints().keySet() ) { if( !names.contains( name ) ) throw new PlannerException( "named checkpoint declared in FlowDef, but no named branch found in pipe assembly: '" + name + "'" ); Set<Pipe> pipes = new HashSet<Pipe>( asList( Pipe.named( name, flowTails ) ) ); int count = 0; for( Pipe pipe : pipes ) { if( pipe instanceof Checkpoint ) count++; } if( count == 0 ) throw new PlannerException( "no checkpoint pipe with branch name found in pipe assembly: '" + name + "'" ); if( count > 1 ) throw new PlannerException( "more than one checkpoint pipe with branch name found in pipe assembly: '" + name + "'" ); } }
@Test public void testGetNames() { Pipe pipe = new Pipe( "first" ); pipe = new NestedSubAssembly( pipe ); Pipe pipe1 = new Pipe( "fifth", ( (SubAssembly) pipe ).getTails()[ 0 ] ); Pipe pipe2 = new Pipe( "sixth", ( (SubAssembly) pipe ).getTails()[ 1 ] ); assertEquals( 6, Pipe.names( pipe1, pipe2 ).length ); assertEquals( 1, Pipe.named( "second", pipe1, pipe2 ).length ); assertEquals( 1, Pipe.named( "sixth", pipe1, pipe2 ).length ); assertEquals( pipe2, Pipe.named( "sixth", pipe1, pipe2 )[ 0 ] ); } }