def test_codegen_simple(self): build_request = BuildRequest(goals=["compile"], addressable_roots=[self.java.address]) execution_graph = self.scheduler.execution_graph(build_request) plans = list(execution_graph.walk()) self.assertEqual(4, len(plans)) thrift_jars = [ Jar(org="org.apache.thrift", name="libthrift", rev="0.9.2"), Jar(org="commons-lang", name="commons-lang", rev="2.5"), self.graph.resolve(Address.parse("src/thrift:slf4j-api")), ] jars = [self.guava] + thrift_jars # Independent leaves 1st self.assertEqual( { ( Sources.of(".java"), Plan( func_or_task_type=gen_apache_thrift, subjects=[self.thrift], strict=True, rev="0.9.2", gen="java", sources=["src/thrift/codegen/simple/simple.thrift"], ), ), (Classpath, Plan(func_or_task_type=IvyResolve, subjects=jars, jars=jars)), }, set(self.extract_product_type_and_plan(p) for p in plans[0:2]), ) # The rest is linked. self.assertEqual( ( Classpath, Plan( func_or_task_type=Javac, subjects=[self.thrift], sources=Promise(Sources.of(".java"), self.thrift), classpath=[Promise(Classpath, jar) for jar in thrift_jars], ), ), self.extract_product_type_and_plan(plans[2]), ) self.assertEqual( ( Classpath, Plan( func_or_task_type=Javac, subjects=[self.java], sources=["src/java/codegen/simple/Simple.java"], classpath=[Promise(Classpath, self.guava), Promise(Classpath, self.thrift)], ), ), self.extract_product_type_and_plan(plans[3]), )
def assert_engine_fail_slow(self, engine): build_request = BuildRequest( goals=['compile'], addressable_roots=[self.java.address, self.java_fail_slow.address]) result = engine.execute(build_request, fail_slow=True) self.assertEqual({Promise(Classpath, self.java): Javac.fake_product()}, result.root_products) self.assertIsInstance(result.error, Engine.PartialFailureError) self.assertEqual(1, len(result.error.failed_to_produce)) failed_promise = Promise(Classpath, self.java_fail_slow) failed_to_produce = result.error.failed_to_produce[failed_promise] failing_configuration = self.failing_thrift.select_configuration( 'failing') self.assertEqual([ Promise(Sources.of('.java'), self.failing_thrift, failing_configuration), Promise(Classpath, self.failing_thrift, failing_configuration), Promise(Classpath, self.java_fail_slow) ], [ftp.promise for ftp in failed_to_produce.walk(postorder=True)]) errors = [ftp.error for ftp in failed_to_produce.walk(postorder=True)] self.assertEqual(3, len(errors)) root_error = errors[0] self.assertIsInstance(root_error, ApacheThriftError) self.assertEqual([None, None], errors[1:])
def test_codegen_simple(self): build_request = BuildRequest(goals=['compile'], addressable_roots=[self.java.address]) execution_graph = self.scheduler.execution_graph(build_request) plans = list(execution_graph.walk()) self.assertEqual(4, len(plans)) thrift_jars = [ Jar(org='org.apache.thrift', name='libthrift', rev='0.9.2'), Jar(org='commons-lang', name='commons-lang', rev='2.5'), self.graph.resolve(Address.parse('src/thrift:slf4j-api')) ] jars = [self.guava] + thrift_jars # Independent leaves 1st self.assertEqual( {(Sources.of('.java'), Plan(func_or_task_type=gen_apache_thrift, subjects=[self.thrift], strict=True, rev='0.9.2', gen='java', sources=['src/thrift/codegen/simple/simple.thrift'])), (Classpath, Plan(func_or_task_type=IvyResolve, subjects=jars, jars=jars))}, set(self.extract_product_type_and_plan(p) for p in plans[0:2])) # The rest is linked. self.assertEqual( (Classpath, Plan(func_or_task_type=Javac, subjects=[self.thrift], sources=Promise(Sources.of('.java'), self.thrift), classpath=[Promise(Classpath, jar) for jar in thrift_jars])), self.extract_product_type_and_plan(plans[2])) self.assertEqual((Classpath, Plan(func_or_task_type=Javac, subjects=[self.java], sources=['src/java/codegen/simple/Simple.java'], classpath=[ Promise(Classpath, self.guava), Promise(Classpath, self.thrift) ])), self.extract_product_type_and_plan(plans[3]))
def test_gen_noop(self): # TODO(John Sirois): Ask around - is this OK? # This is different than today. There is a gen'able target reachable from the java target, but # the scheduler 'pull-seeding' has ApacheThriftPlanner stopping short since the subject it's # handed is not thrift. build_request = BuildRequest(goals=['gen'], addressable_roots=[self.java.address]) execution_graph = self.scheduler.execution_graph(build_request) plans = list(execution_graph.walk()) self.assertEqual(1, len(plans)) self.assertEqual((Sources.of('.java'), Plan(func_or_task_type=lift_native_product, subjects=[self.java], subject=self.java, product_type=Sources.of('.java'))), self.extract_product_type_and_plan(plans[0]))
def test_codegen_simple(self): build_request = BuildRequest(goals=['compile'], addressable_roots=[self.java.address]) execution_graph = self.scheduler.execution_graph(build_request) plans = list(execution_graph.walk()) self.assertEqual(4, len(plans)) thrift_jars = [Jar(org='org.apache.thrift', name='libthrift', rev='0.9.2'), Jar(org='commons-lang', name='commons-lang', rev='2.5'), self.graph.resolve(Address.parse('src/thrift:slf4j-api'))] jars = [self.guava] + thrift_jars # Independent leaves 1st self.assertEqual({(Sources.of('.java'), Plan(func_or_task_type=gen_apache_thrift, subjects=[self.thrift], strict=True, rev='0.9.2', gen='java', sources=['src/thrift/codegen/simple/simple.thrift'])), (Classpath, Plan(func_or_task_type=IvyResolve, subjects=jars, jars=jars))}, set(plans[0:2])) # The rest is linked. self.assertEqual((Classpath, Plan(func_or_task_type=Javac, subjects=[self.thrift], sources=Promise(Sources.of('.java'), self.thrift), classpath=[Promise(Classpath, jar) for jar in thrift_jars])), plans[2]) self.assertEqual((Classpath, Plan(func_or_task_type=Javac, subjects=[self.java], sources=['src/java/codegen/simple/Simple.java'], classpath=[Promise(Classpath, self.guava), Promise(Classpath, self.thrift)])), plans[3])
def test_gen_noop(self): # TODO(John Sirois): Ask around - is this OK? # This is different than today. There is a gen'able target reachable from the java target, but # the scheduler 'pull-seeding' has ApacheThriftPlanner stopping short since the subject it's # handed is not thrift. build_request = BuildRequest(goals=["gen"], addressable_roots=[self.java.address]) execution_graph = self.scheduler.execution_graph(build_request) plans = list(execution_graph.walk()) self.assertEqual(1, len(plans)) self.assertEqual( ( Sources.of(".java"), Plan( func_or_task_type=lift_native_product, subjects=[self.java], subject=self.java, product_type=Sources.of(".java"), ), ), self.extract_product_type_and_plan(plans[0]), )
def test_gen(self): build_request = BuildRequest(goals=['gen'], addressable_roots=[self.thrift.address]) execution_graph = self.scheduler.execution_graph(build_request) plans = list(execution_graph.walk()) self.assertEqual(1, len(plans)) self.assertEqual((Sources.of('.java'), Plan(func_or_task_type=gen_apache_thrift, subjects=[self.thrift], strict=True, rev='0.9.2', gen='java', sources=['src/thrift/codegen/simple/simple.thrift'])), plans[0])
def test_gen(self): build_request = BuildRequest(goals=['gen'], addressable_roots=[self.thrift.address]) execution_graph = self.scheduler.execution_graph(build_request) plans = list(execution_graph.walk()) self.assertEqual(1, len(plans)) self.assertEqual((Sources.of('.java'), Plan(func_or_task_type=gen_apache_thrift, subjects=[self.thrift], strict=True, rev='0.9.2', gen='java', sources=['src/thrift/codegen/simple/simple.thrift'])), self.extract_product_type_and_plan(plans[0]))
def test_gen(self): build_request = BuildRequest(goals=["gen"], addressable_roots=[self.thrift.address]) execution_graph = self.scheduler.execution_graph(build_request) plans = list(execution_graph.walk()) self.assertEqual(1, len(plans)) self.assertEqual( ( Sources.of(".java"), Plan( func_or_task_type=gen_apache_thrift, subjects=[self.thrift], strict=True, rev="0.9.2", gen="java", sources=["src/thrift/codegen/simple/simple.thrift"], ), ), self.extract_product_type_and_plan(plans[0]), )
def assert_engine_fail_slow(self, engine): build_request = BuildRequest(goals=['compile'], addressable_roots=[self.java.address, self.java_fail_slow.address]) result = engine.execute(build_request, fail_slow=True) self.assertEqual({Promise(Classpath, self.java): Javac.fake_product()}, result.root_products) self.assertIsInstance(result.error, Engine.PartialFailureError) self.assertEqual(1, len(result.error.failed_to_produce)) failed_promise = Promise(Classpath, self.java_fail_slow) failed_to_produce = result.error.failed_to_produce[failed_promise] failing_configuration = self.failing_thrift.select_configuration('failing') self.assertEqual([Promise(Sources.of('.java'), self.failing_thrift, failing_configuration), Promise(Classpath, self.failing_thrift, failing_configuration), Promise(Classpath, self.java_fail_slow)], [ftp.promise for ftp in failed_to_produce.walk(postorder=True)]) errors = [ftp.error for ftp in failed_to_produce.walk(postorder=True)] self.assertEqual(3, len(errors)) root_error = errors[0] self.assertIsInstance(root_error, ApacheThriftError) self.assertEqual([None, None], errors[1:])