コード例 #1
0
ファイル: SourceTest.java プロジェクト: hochgi/akka
  @Test
  public void mustBeAbleToRecover() throws Exception {
    final ManualProbe<Integer> publisherProbe = TestPublisher.manualProbe(true, system);
    final JavaTestKit probe = new JavaTestKit(system);

    final Source<Integer, NotUsed> source =
        Source.fromPublisher(publisherProbe)
            .map(
                elem -> {
                  if (elem == 1) throw new RuntimeException("ex");
                  else return elem;
                })
            .recover(new PFBuilder<Throwable, Integer>().matchAny(ex -> 0).build());

    final CompletionStage<Done> future =
        source.runWith(
            Sink.foreach(elem -> probe.getRef().tell(elem, ActorRef.noSender())), materializer);
    final PublisherProbeSubscription<Integer> s = publisherProbe.expectSubscription();
    s.sendNext(0);
    probe.expectMsgEquals(0);
    s.sendNext(1);
    probe.expectMsgEquals(0);

    future.toCompletableFuture().get(200, TimeUnit.MILLISECONDS);
  }
コード例 #2
0
ファイル: CompositionDocTest.java プロジェクト: ALPHA-60/akka
  @Test
  public void reusingComponents() throws Exception {
    final Source<Integer, NotUsed> nestedSource =
        Source.single(0) // An atomic source
            .map(i -> i + 1) // an atomic processing stage
            .named("nestedSource"); // wraps up the current Source and gives it a name

    final Flow<Integer, Integer, NotUsed> nestedFlow =
        Flow.of(Integer.class)
            .filter(i -> i != 0) // an atomic processing stage
            .map(i -> i - 2) // another atomic processing stage
            .named("nestedFlow"); // wraps up the Flow, and gives it a name

    final Sink<Integer, NotUsed> nestedSink =
        nestedFlow
            .to(Sink.fold(0, (acc, i) -> acc + i)) // wire an atomic sink to the nestedFlow
            .named("nestedSink"); // wrap it up

    // #reuse
    // Create a RunnableGraph from our components
    final RunnableGraph<NotUsed> runnableGraph = nestedSource.to(nestedSink);

    // Usage is uniform, no matter if modules are composite or atomic
    final RunnableGraph<NotUsed> runnableGraph2 =
        Source.single(0).to(Sink.fold(0, (acc, i) -> acc + i));
    // #reuse
  }
コード例 #3
0
  /**
   * Method removes a Spring bean definition from the XML application context file. Bean definition
   * is identified by its id or bean name.
   *
   * @param project
   * @param id
   */
  public void removeBeanDefinition(File configFile, Project project, String id) {
    Source xsltSource;
    Source xmlSource;
    try {
      xsltSource =
          new StreamSource(new ClassPathResource("transform/delete-bean.xsl").getInputStream());
      xsltSource.setSystemId("delete-bean");

      List<File> configFiles = new ArrayList<>();
      configFiles.add(configFile);
      configFiles.addAll(getConfigImports(configFile, project));

      for (File file : configFiles) {
        xmlSource = new StringSource(FileUtils.readToString(new FileInputStream(configFile)));

        // create transformer
        Transformer transformer = transformerFactory.newTransformer(xsltSource);
        transformer.setParameter("bean_id", id);

        // transform
        StringResult result = new StringResult();
        transformer.transform(xmlSource, result);
        FileUtils.writeToFile(format(result.toString(), project.getSettings().getTabSize()), file);
        return;
      }
    } catch (IOException e) {
      throw new ApplicationRuntimeException(UNABLE_TO_READ_TRANSFORMATION_SOURCE, e);
    } catch (TransformerException e) {
      throw new ApplicationRuntimeException(FAILED_TO_UPDATE_BEAN_DEFINITION, e);
    }
  }
コード例 #4
0
ファイル: SourceTest.java プロジェクト: hochgi/akka
  @Test
  public void mustBeAbleToUseZipWith() throws Exception {
    final JavaTestKit probe = new JavaTestKit(system);
    final Iterable<String> input1 = Arrays.asList("A", "B", "C");
    final Iterable<String> input2 = Arrays.asList("D", "E", "F");

    Source.from(input1)
        .zipWith(
            Source.from(input2),
            new Function2<String, String, String>() {
              public String apply(String s1, String s2) {
                return s1 + "-" + s2;
              }
            })
        .runForeach(
            new Procedure<String>() {
              public void apply(String elem) {
                probe.getRef().tell(elem, ActorRef.noSender());
              }
            },
            materializer);

    probe.expectMsgEquals("A-D");
    probe.expectMsgEquals("B-E");
    probe.expectMsgEquals("C-F");
  }
コード例 #5
0
ファイル: Issue45TestCase.java プロジェクト: patterncat/orika
  /*
   * We need a type which can be resolved 2 different ways:
   *
   * SourceChild == Source : mapping SourceChild == SourceChild : converter
   */
  @Test
  public void testResolveTypes2() {

    MapperFacade mapper = new MyMapper();

    Source src = new Source();
    src.name = "source 1";
    src.description = "source 1 description";

    SourceChild srcChild = new SourceChild();
    srcChild.name = "source 1";
    srcChild.description = "source 1 description";

    /*
     * Mapping Source to Dest2 causes a mapping to be created
     */
    Dest2 dest2 = mapper.map(src, Dest2.class);
    /*
     * SourceChild is able to use this mapping, so the resolved type in this
     * case for SourceChild is 'Source', which gets cached in resolvedTypes
     */
    Dest2 dest2B = mapper.map(srcChild, Dest2.class);

    Assert.assertNotNull(dest2);
    Assert.assertNotNull(dest2B);

    /*
     * But now, since the resolvedType for 'SourceChild' has been cached as
     * 'Source', it cannot find the converter which has been specifically
     * created for 'SourceChild'
     */
    Dest1 dest1 = mapper.map(srcChild, Dest1.class);
    Assert.assertNotNull(dest1);
  }
コード例 #6
0
  private void completeEvidenceDocument() throws IOException {

    String tempText =
        "<table><tr><td class=\"subHeading\">Evidence:</td><td class=\"info\">"
            + this.theEvidence.getName()
            + "</td></tr>\n";

    // add the type of evidence
    tempText +=
        "<tr><td class=\"subHeading\">Type:</td><td class=\"info\">"
            + this.theEvidence.getType()
            + "</td></tr>\n";

    // add the evidence description
    tempText +=
        "<tr><td class=\"subHeading\">Description:</td><td class=\"info\">"
            + this.theEvidence.getDescription()
            + "</td></tr>\n";

    // add the sources relating to the given piece of evidence
    tempText += "<tr><td class=\"subHeading\">References:</td><td class=\"info\" colspan=\"3\">\n";

    for (Source s : this.theEvidence.getSources(allTheSources)) {
      tempText +=
          "\t<li><a href=\"../source/" + s.getName() + ".html\">" + s.getName() + "</a></li>\n";
    }

    tempText += "</td></tr>\n";
    // tempText +="</body></html>";
    tempText +=
        "</table></div>\n<div id=\"footer\">\n\t&copy; "
            + getYear()
            + " <a href=\"http://www.eecs.qmul.ac.uk/research/view/risk-and-information-management\"> Risk and Information Management (RIM) Research Group, Queen Mary, University of London</a>\n</div>\n</body>\n</html>";
    appendCurrentDocument(tempText, "evidence");
  }
コード例 #7
0
  /**
   * Method adds a new Spring bean definition to the XML application context file.
   *
   * @param project
   * @param jaxbElement
   */
  public void addBeanDefinition(File configFile, Project project, Object jaxbElement) {
    Source xsltSource;
    Source xmlSource;
    try {
      xsltSource =
          new StreamSource(new ClassPathResource("transform/add-bean.xsl").getInputStream());
      xsltSource.setSystemId("add-bean");
      xmlSource = new StringSource(FileUtils.readToString(new FileInputStream(configFile)));

      // create transformer
      Transformer transformer = transformerFactory.newTransformer(xsltSource);
      transformer.setParameter(
          "bean_content",
          getXmlContent(jaxbElement)
              .replaceAll("(?m)^(.)", getTabs(1, project.getSettings().getTabSize()) + "$1"));

      // transform
      StringResult result = new StringResult();
      transformer.transform(xmlSource, result);
      FileUtils.writeToFile(
          format(result.toString(), project.getSettings().getTabSize()), configFile);
      return;
    } catch (IOException e) {
      throw new ApplicationRuntimeException(UNABLE_TO_READ_TRANSFORMATION_SOURCE, e);
    } catch (TransformerException e) {
      throw new ApplicationRuntimeException(FAILED_TO_UPDATE_BEAN_DEFINITION, e);
    }
  }
コード例 #8
0
  /**
   * Return the Properties that enumerate the keys for this Source
   *
   * @param source the Source
   * @return the relevant Properties
   */
  protected static Properties getKeyProperties(Source source) {
    Properties keys = null;
    synchronized (sourceKeys) {
      keys = sourceKeys.get(source);
      if (keys == null) {
        String sourceNameKeysFileName = source.getName() + "_keys.properties";
        keys = PropertiesUtil.loadProperties(sourceNameKeysFileName);

        String sourceTypeKeysFileName = source.getType() + "_keys.properties";
        if (keys == null) {
          keys = PropertiesUtil.loadProperties(sourceTypeKeysFileName);
        }

        if (keys == null) {
          throw new RuntimeException(
              "can't find keys for source: "
                  + source
                  + " after trying to find: "
                  + sourceNameKeysFileName
                  + " and: "
                  + sourceTypeKeysFileName);
        }

        sourceKeys.put(source, keys);
      }
    }
    return keys;
  }
コード例 #9
0
  /**
   * Adds a new streaming source to the list. If another source in the list is already playing on
   * the same channel, it is stopped and removed from the list.
   *
   * @param source New source to stream.
   */
  public void watch(Source source) {
    // make sure the source exists:
    if (source == null) return;

    // make sure we aren't already watching this source:
    if (streamingSources.contains(source)) return;

    ListIterator<Source> iter;
    Source src;

    // Make sure noone else is accessing the list of sources:
    synchronized (listLock) {
      // Any currently watched source which is null or playing on the
      // same channel as the new source should be stopped and removed
      // from the list.
      iter = streamingSources.listIterator();
      while (iter.hasNext()) {
        src = iter.next();
        if (src == null) {
          iter.remove();
        } else if (source.channel == src.channel) {
          src.stop();
          iter.remove();
        }
      }

      // Add the new source to the list:
      streamingSources.add(source);
    }
  }
コード例 #10
0
ファイル: CDSXMatch.java プロジェクト: jankotek/asterope
 /**
  * @param pcat
  * @param array
  * @param coordTab
  * @param flagIgnore
  */
 private static void fillXMatchArray(
     Pcat pcat, double[][] array, int[] coordTab, boolean[] flagIgnore) {
   Source o;
   String content;
   Iterator<Obj> it = pcat.iterator();
   for (int i = 0; it.hasNext(); i++) {
     o = (Source) it.next();
     // not needed
     //            flagIgnore[i] = false;
     try {
       // ra
       content = o.getValue(coordTab[0]);
       if (isSexa(content)) content = sexa2Deg(content, true);
       // array[i][0] = Double.parseDouble(content);
       array[i][0] = Double.valueOf(content).doubleValue();
       // dec
       content = o.getValue(coordTab[1]);
       if (isSexa(content)) content = sexa2Deg(content, false);
       // array[i][1] = Double.parseDouble(content);
       array[i][1] = Double.valueOf(content).doubleValue();
     } catch (NumberFormatException e) {
       e.printStackTrace();
       // ignore this source
       flagIgnore[i] = true;
       //                array[i][0] = array[i][1] = 0.0;
     } catch (NullPointerException npe) {
       npe.printStackTrace();
       // ignore this source
       flagIgnore[i] = true;
     }
   }
 }
コード例 #11
0
  @Test
  public void testAssociateFile() throws Exception {
    sm.register(SOURCE, testFile);
    String statistics = "statistics";
    Source source = sm.getSource(SOURCE);
    String rcStr = associateFile(source, statistics);

    assertEquals(sm.getSource(SOURCE).getFilePropertyNames().length, 1);

    sm.saveStatus();

    sm.shutdown();
    sm.init();

    assertEquals(sm.getSource(SOURCE).getFilePropertyNames().length, 1);

    String statsContent = source.getFilePropertyContentsAsString(statistics);
    assertEquals(statsContent, rcStr);

    File f = source.getFileProperty(statistics);
    DataInputStream dis = new DataInputStream(new FileInputStream(f));
    byte[] content = new byte[dis.available()];
    dis.readFully(content);
    assertEquals(new String(content), rcStr);
  }
コード例 #12
0
 @Test
 public void testReturnNullWhenNoProperty() throws Exception {
   sm.register(SOURCE, testFile);
   Source source = sm.getSource(SOURCE);
   assertNull(source.getFileProperty("skjbnskb"));
   assertNull(source.getProperty("skjbnskb"));
 }
コード例 #13
0
ファイル: RMManager.java プロジェクト: eonezhang/cxf
  private void recoverSourceSequence(
      Endpoint endpoint, Conduit conduit, Source s, SourceSequence ss) {
    Collection<RMMessage> ms = store.getMessages(ss.getIdentifier(), true);
    if (null == ms || 0 == ms.size()) {
      store.removeSourceSequence(ss.getIdentifier());
      return;
    }
    LOG.log(Level.FINE, "Number of messages in sequence: {0}", ms.size());

    s.addSequence(ss, false);
    // choosing an arbitrary valid source sequence as the current source sequence
    if (s.getAssociatedSequence(null) == null && !ss.isExpired() && !ss.isLastMessage()) {
      s.setCurrent(ss);
    }
    for (RMMessage m : ms) {

      Message message = new MessageImpl();
      Exchange exchange = new ExchangeImpl();
      message.setExchange(exchange);
      exchange.setOutMessage(message);
      if (null != conduit) {
        exchange.setConduit(conduit);
        message.put(Message.REQUESTOR_ROLE, Boolean.TRUE);
      }
      exchange.put(Endpoint.class, endpoint);
      exchange.put(Service.class, endpoint.getService());
      exchange.put(Binding.class, endpoint.getBinding());
      exchange.put(Bus.class, bus);

      SequenceType st = new SequenceType();
      st.setIdentifier(ss.getIdentifier());
      st.setMessageNumber(m.getMessageNumber());
      RMProperties rmps = new RMProperties();
      rmps.setSequence(st);
      rmps.exposeAs(ss.getProtocol().getWSRMNamespace());
      if (ss.isLastMessage() && ss.getCurrentMessageNr() == m.getMessageNumber()) {
        CloseSequenceType close = new CloseSequenceType();
        close.setIdentifier(ss.getIdentifier());
        rmps.setCloseSequence(close);
      }
      RMContextUtils.storeRMProperties(message, rmps, true);
      if (null == conduit) {
        String to = m.getTo();
        AddressingProperties maps = new AddressingProperties();
        maps.setTo(RMUtils.createReference(to));
        RMContextUtils.storeMAPs(maps, message, true, false);
      }

      try {
        // RMMessage is stored in a serialized way, therefore
        // RMMessage content must be splitted into soap root message
        // and attachments
        PersistenceUtils.decodeRMContent(m, message);
        RMContextUtils.setProtocolVariation(message, ss.getProtocol());
        retransmissionQueue.addUnacknowledged(message);
      } catch (IOException e) {
        LOG.log(Level.SEVERE, "Error reading persisted message data", e);
      }
    }
  }
コード例 #14
0
  @Test
  public void testOverrideFileProperty() throws Exception {
    sm.register(SOURCE, testFile);
    Source source = sm.getSource(SOURCE);
    String fileProp = "testFileProp";
    associateFile(source, fileProp);

    File file = source.createFileProperty(fileProp);
    FileOutputStream fis = new FileOutputStream(file);
    fis.write("newcontent".getBytes());
    fis.close();

    source.deleteProperty(fileProp);
    File dir = sm.getSourceInfoDirectory();
    File[] content =
        dir.listFiles(
            new FilenameFilter() {

              @Override
              public boolean accept(File dir, String name) {
                return !name.startsWith(".");
              }
            });
    assertEquals(2, content.length);
    String[] res = new String[] {content[0].getName(), content[1].getName()};
    Arrays.sort(res);
    String[] comp = new String[] {"directory.xml", "spatial_ref_sys_extended.gdms"};
    assertArrayEquals(res, comp);
  }
コード例 #15
0
  @Test
  public void shouldMapWithCustomizedClassMapBuilder() {
    // given
    MapperFactory mapperFactory =
        new DefaultMapperFactory.Builder()
            .classMapBuilderFactory(new ScoringClassMapBuilder.Factory())
            .build();

    mapperFactory.classMap(Source.class, Destination.class).byDefault().register();

    MapperFacade mapperFacade = mapperFactory.getMapperFacade();

    Source src = new Source();
    src.firstName = "Jan";
    src.postalAddress = new PostalAddress();
    src.postalAddress.country = new Country();
    src.postalAddress.country.alphaCode = "PL";

    // when
    Destination result = mapperFacade.map(src, Destination.class);

    // then
    assertThat(result.name.first).isEqualTo("Jan");
    assertThat(result.countryCode).isEqualTo("PL");
  }
コード例 #16
0
 /**
  * Returns a string representation of this object useful for debugging purposes.
  *
  * <p>The output includes details of all the {@link #getRegisteredOutputSegments() registered
  * output segments}.
  *
  * @return a string representation of this object useful for debugging purposes.
  */
 public String getDebugInfo() {
   StringBuffer sb = new StringBuffer();
   for (Iterator i = getRegisteredOutputSegments().iterator(); i.hasNext(); ) {
     OutputSegment outputSegment = (OutputSegment) i.next();
     if (outputSegment instanceof BlankOutputSegment) sb.append("Replace with Spaces: ");
     else if (outputSegment instanceof RemoveOutputSegment) sb.append("Remove: ");
     else sb.append("Replace: ");
     if (sourceText instanceof Source) {
       Source source = (Source) sourceText;
       sb.append('(');
       source.getRowColumnVector(outputSegment.getBegin()).appendTo(sb);
       sb.append('-');
       source.getRowColumnVector(outputSegment.getEnd()).appendTo(sb);
       sb.append(')');
     } else {
       sb.append("(p")
           .append(outputSegment.getBegin())
           .append("-p")
           .append(outputSegment.getEnd())
           .append(')');
     }
     sb.append(' ');
     String outputFromSegment = outputSegment.toString();
     if (outputFromSegment.length() <= 20) {
       sb.append(outputFromSegment);
     } else {
       sb.append(outputFromSegment.substring(0, 20)).append("...");
     }
     sb.append(Config.NewLine);
   }
   return sb.toString();
 }
コード例 #17
0
ファイル: SourceTest.java プロジェクト: hochgi/akka
 @Test
 public void mustProduceTicks() throws Exception {
   final JavaTestKit probe = new JavaTestKit(system);
   Source<String, Cancellable> tickSource =
       Source.tick(
           FiniteDuration.create(1, TimeUnit.SECONDS),
           FiniteDuration.create(500, TimeUnit.MILLISECONDS),
           "tick");
   @SuppressWarnings("unused")
   Cancellable cancellable =
       tickSource
           .to(
               Sink.foreach(
                   new Procedure<String>() {
                     public void apply(String elem) {
                       probe.getRef().tell(elem, ActorRef.noSender());
                     }
                   }))
           .run(materializer);
   probe.expectNoMsg(FiniteDuration.create(600, TimeUnit.MILLISECONDS));
   probe.expectMsgEquals("tick");
   probe.expectNoMsg(FiniteDuration.create(200, TimeUnit.MILLISECONDS));
   probe.expectMsgEquals("tick");
   probe.expectNoMsg(FiniteDuration.create(200, TimeUnit.MILLISECONDS));
 }
コード例 #18
0
 /** Specify which classes are visible to the compiler through -classpath. */
 public void setVisibleClasses(Map<String, Source> vs) {
   visibleSrcs = new HashSet<>();
   for (String s : vs.keySet()) {
     Source src = vs.get(s);
     visibleSrcs.add(src.file().toURI());
   }
 }
コード例 #19
0
ファイル: SourceTest.java プロジェクト: hochgi/akka
  @Test
  public void mustBeAbleToUseFlatMapMerge() throws Exception {
    final JavaTestKit probe = new JavaTestKit(system);
    final Iterable<Integer> input1 = Arrays.asList(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
    final Iterable<Integer> input2 = Arrays.asList(10, 11, 12, 13, 14, 15, 16, 17, 18, 19);
    final Iterable<Integer> input3 = Arrays.asList(20, 21, 22, 23, 24, 25, 26, 27, 28, 29);
    final Iterable<Integer> input4 = Arrays.asList(30, 31, 32, 33, 34, 35, 36, 37, 38, 39);

    final List<Source<Integer, NotUsed>> mainInputs = new ArrayList<Source<Integer, NotUsed>>();
    mainInputs.add(Source.from(input1));
    mainInputs.add(Source.from(input2));
    mainInputs.add(Source.from(input3));
    mainInputs.add(Source.from(input4));

    CompletionStage<List<Integer>> future =
        Source.from(mainInputs)
            .flatMapMerge(3, ConstantFun.<Source<Integer, NotUsed>>javaIdentityFunction())
            .grouped(60)
            .runWith(Sink.<List<Integer>>head(), materializer);

    List<Integer> result = future.toCompletableFuture().get(3, TimeUnit.SECONDS);
    final Set<Integer> set = new HashSet<Integer>();
    for (Integer i : result) {
      set.add(i);
    }
    final Set<Integer> expected = new HashSet<Integer>();
    for (int i = 0; i < 40; ++i) {
      expected.add(i);
    }

    assertEquals(expected, set);
  }
コード例 #20
0
 private void addDefaultProperties() {
   for (Iterator it = m_sources.iterator(); it.hasNext(); ) {
     Source source = (Source) it.next();
     makePathLoadable(source.getPath());
     addFetchedPaths(source.getPath(), source.getObjectType());
   }
 }
コード例 #21
0
ファイル: Expression.java プロジェクト: Vivekpande26/midpoint
 private void appendTraceHeader(
     StringBuilder sb,
     ExpressionEvaluationContext context,
     ExpressionVariables processedVariables) {
   sb.append("---[ EXPRESSION in ");
   sb.append(context.getContextDescription());
   sb.append("]---------------------------");
   sb.append("\nSources:");
   Collection<Source<?, ?>> sources = context.getSources();
   if (sources == null) {
     sb.append(" null");
   } else {
     for (Source<?, ?> source : sources) {
       sb.append("\n");
       sb.append(source.debugDump(1));
     }
   }
   sb.append("\nVariables:");
   if (processedVariables == null) {
     sb.append(" null");
   } else {
     sb.append("\n");
     sb.append(processedVariables.debugDump(1));
   }
   sb.append("\nOutput definition: ").append(MiscUtil.toString(outputDefinition));
   sb.append("\nEvaluators: ");
   sb.append(shortDebugDump());
 }
コード例 #22
0
  /**
   * Implements the progressive text handling. This method is used as a "web method" with
   * progressiveText.jelly.
   */
  public void doProgressText(StaplerRequest req, StaplerResponse rsp) throws IOException {
    setContentType(rsp);
    rsp.setStatus(HttpServletResponse.SC_OK);

    if (!source.exists()) {
      // file doesn't exist yet
      rsp.addHeader("X-Text-Size", "0");
      rsp.addHeader("X-More-Data", "true");
      return;
    }

    long start = 0;
    String s = req.getParameter("start");
    if (s != null) start = Long.parseLong(s);

    if (source.length() < start) start = 0; // text rolled over

    CharSpool spool = new CharSpool();
    long r = writeLogTo(start, spool);

    rsp.addHeader("X-Text-Size", String.valueOf(r));
    if (!completed) rsp.addHeader("X-More-Data", "true");

    Writer w = createWriter(req, rsp, r - start);
    spool.writeTo(new LineEndNormalizingWriter(w));
    w.close();
  }
コード例 #23
0
ファイル: CDSXMatch.java プロジェクト: jankotek/asterope
 private void fillXIDArray(Pcat pcat, String[] array, int index) {
   Source o;
   Iterator<Obj> it = pcat.iterator();
   for (int i = 0; it.hasNext(); i++) {
     o = (Source) it.next();
     array[i] = o.getValue(index);
   }
 }
コード例 #24
0
 static Source createSource(
     final String key, final SourceType type, final Map<String, String> fields) {
   Source source = new Source();
   source.key = key;
   source.type = type;
   source.fields = fields;
   return source;
 }
コード例 #25
0
 public void go() {
   source.start();
   source.waitFor();
   if (sink != null) {
     sink.close();
   }
   stats.print();
 }
コード例 #26
0
ファイル: SourceTest.java プロジェクト: hochgi/akka
 @Test
 public void mustWorkFromFuture() throws Exception {
   final Iterable<String> input = Arrays.asList("A", "B", "C");
   CompletionStage<String> future1 = Source.from(input).runWith(Sink.<String>head(), materializer);
   CompletionStage<String> future2 =
       Source.fromCompletionStage(future1).runWith(Sink.<String>head(), materializer);
   String result = future2.toCompletableFuture().get(3, TimeUnit.SECONDS);
   assertEquals("A", result);
 }
コード例 #27
0
ファイル: SourceImpl.java プロジェクト: graalvm/truffle
 @TruffleBoundary
 @Override
 public boolean equals(Object obj) {
   if (obj instanceof Source) {
     Source other = (Source) obj;
     return content().equals(other.content()) && equalAttributes(other);
   }
   return false;
 }
コード例 #28
0
ファイル: OkioTest.java プロジェクト: happysir/okio
 @Test
 public void sourceFromInputStreamBounds() throws Exception {
   Source source = Okio.source(new ByteArrayInputStream(new byte[100]));
   try {
     source.read(new Buffer(), -1);
     fail();
   } catch (IllegalArgumentException expected) {
   }
 }
コード例 #29
0
ファイル: ConfigTest.java プロジェクト: Chessray/mapstruct
  @Test
  @WithClasses({Target.class, SourceTargetMapper.class})
  public void shouldUseCustomMapperViaMapperConfigForFooToDto() {

    Source source = SourceTargetMapper.INSTANCE.toSource(new Target(new FooEntity()));
    assertThat(source.getFoo()).isNotNull();
    assertThat(source.getFoo().getCreatedBy())
        .isEqualTo(CustomMapperViaMapperConfig.class.getSimpleName());
  }
コード例 #30
0
 protected void say(Source source, String str) {
   Server server = source.getServer();
   if (source.talkable()) {
     source.messageReceived(server.getNick(), str);
     server.say(source.getName(), str);
   } else {
     source.report(getText(IRCTextProvider.INTERPRETOR_NOT_ON_CHANNEL));
   }
 }