SecureComputationEngineImpl implements SecureComputationEngine<ResourcePoolT, BuilderT> { @Override public <OutputT> OutputT runApplication(Application<OutputT, BuilderT> application, ResourcePoolT resourcePool, Network network, Duration timeout) { Future<OutputT> future = startApplication(application, resourcePool, network); try { return future.get(timeout.toNanos(), TimeUnit.NANOSECONDS); } catch (InterruptedException | TimeoutException e) { throw new RuntimeException("Internal error in waiting", e); } catch (ExecutionException e) { throw new RuntimeException("Execution exception when running the application", e.getCause()); } } SecureComputationEngineImpl(ProtocolSuite<ResourcePoolT, BuilderT> protocolSuite,
      ProtocolEvaluator<ResourcePoolT> evaluator); @Override OutputT runApplication(Application<OutputT, BuilderT> application,
      ResourcePoolT resourcePool, Network network, Duration timeout); @Override Future<OutputT> startApplication(Application<OutputT, BuilderT> application,
      ResourcePoolT resourcePool, Network network); @Override synchronized void setup(); @Override synchronized void shutdownSCE();  }
@Test public void testRunApplication() { Application<BigInteger, ProtocolBuilderNumeric> app = builder -> { DRes<SInt> a = builder.numeric().known(BigInteger.valueOf(10)); DRes<SInt> b = builder.numeric().known(BigInteger.valueOf(10)); return builder.numeric().open(builder.numeric().add(a, b)); }; DummyArithmeticResourcePool rp = new DummyArithmeticResourcePoolImpl(0, 1, fieldDefinition); BigInteger b = sce.runApplication(app, rp, null); assertThat(b, is(BigInteger.valueOf(20))); }
@Test public void testRunApplicationLong() { Application<BigInteger, ProtocolBuilderNumeric> app = builder -> { DRes<SInt> a = builder.numeric().known(10L); DRes<SInt> b = builder.numeric().known(10L); return builder.numeric().open(builder.numeric().add(a, b)); }; DummyArithmeticResourcePool rp = new DummyArithmeticResourcePoolImpl(0, 1, fieldDefinition); BigInteger b = sce.runApplication(app, rp, null); assertThat(b, is(BigInteger.valueOf(20))); }
@Test(expected = RuntimeException.class) public void testRunApplicationAppThrows() { Application<Object, ProtocolBuilderNumeric> app = builder -> { throw new RuntimeException(); }; DummyArithmeticResourcePool rp = new DummyArithmeticResourcePoolImpl(0, 1, fieldDefinition); sce.runApplication(app, rp, null); fail("Should not be reachable"); }
@Test(expected = RuntimeException.class) public void testRunApplicationAppTimesOut() { Application<Object, ProtocolBuilderNumeric> app = builder -> { while (true) { } }; DummyArithmeticResourcePool rp = new DummyArithmeticResourcePoolImpl(0, 1, fieldDefinition); sce.runApplication(app, rp, null, Duration.ofNanos(1)); fail("Should not be reachable"); }