예제 #1
1
  @Test
  public final void testTotalBoxedLongBoxedLongBoxedLongBoxedLongBoxedLongMoreBoxedLongs() {
    final Long[] numbers1 = convertToBoxed(NUMBERS1);
    final Long[] numbers2 = convertToBoxed(NUMBERS2);

    for (final Long n1 : numbers1) {
      for (final Long n2 : numbers2) {
        for (final Long n3 : numbers1) {
          for (final Long n4 : numbers2) {
            for (final Long n5 : numbers1) {
              @SuppressWarnings("boxing")
              final Long expected1 = (n1 + n2 + n3 + n4 + n5 + n1 + n2 + n3 + n4 + n5);
              @SuppressWarnings("boxing")
              final Long actual1 = total(n1, n2, n3, n4, n5, n1, n2, n3, n4, n5);
              // System.out.println("expected: " + expected1 + "\nactual:   " + actual1);
              assertThat(actual1, is(equalTo(expected1)));

              @SuppressWarnings("boxing")
              final Long expected2 = (n1 + n2 + n3 + n4 + n5 + n1 + n2 + n3 + n4 + n5);
              @SuppressWarnings("boxing")
              final Long actual2 = total(n1, n2, n3, n4, n5, n1, n2, n3, n4, n5);
              // System.out.println("expected: " + expected2 + "\nactual:   " + actual2);
              assertThat(actual2, is(equalTo(expected2)));
            }
          }
        }
      }
    }

    final Long[] numbers3 = new Long[NUMBERS3.length];
    System.arraycopy(convertToBoxed(NUMBERS3), 0, numbers3, 0, NUMBERS3.length);
    final Long[] numbers4 = new Long[NUMBERS4.length];
    System.arraycopy(convertToBoxed(NUMBERS4), 0, numbers4, 0, NUMBERS4.length);

    for (final Long n1 : numbers3) {
      for (final Long n2 : numbers4) {
        for (final Long n3 : numbers3) {
          for (final Long n4 : numbers4) {
            for (final Long n5 : numbers3) {
              @SuppressWarnings("boxing")
              final Long expected3 = (n1 + n2 + n3 + n4 + n5 + n1 + n2 + n3 + n4 + n5);
              @SuppressWarnings("boxing")
              final Long actual3 = total(n1, n2, n3, n4, n5, n1, n2, n3, n4, n5);
              // System.out.println("expected: " + expected3 + "\nactual:   " + actual3);
              assertThat(actual3, is(equalTo(expected3)));

              @SuppressWarnings("boxing")
              final Long expected4 = (n1 + n2 + n3 + n4 + n5 + n1 + n2 + n3 + n4 + n5);
              @SuppressWarnings("boxing")
              final Long actual4 = total(n1, n2, n3, n4, n5, n1, n2, n3, n4, n5);
              // System.out.println("expected: " + expected4 + "\nactual:   " + actual4);
              assertThat(actual4, is(equalTo(expected4)));
            }
          }
        }
      }
    }
  }
예제 #2
1
  @Test
  public final void testSumLongLongLongLongLongLongArray() {
    final long[] numbers1 = NUMBERS1;
    final long[] numbers2 = NUMBERS2;

    for (final long n1 : numbers1) {
      for (final long n2 : numbers2) {
        for (final long n3 : numbers1) {
          for (final long n4 : numbers2) {
            for (final long n5 : numbers1) {

              long total1 = n1 + n2 + n3 + n4 + n5;
              for (final long n : numbers1) total1 += n;

              @SuppressWarnings("boxing")
              final Long expected1 = total1;
              @SuppressWarnings("boxing")
              final Long actual1 = sum(n1, n2, n3, n4, n5, numbers1);
              // System.out.println("expected: " + expected1 + "\nactual:   " + actual1);
              assertThat(actual1, is(equalTo(expected1)));

              long total2 = n1 + n2 + n3 + n4 + n5;
              for (final long n : numbers2) total2 += n;

              @SuppressWarnings("boxing")
              final Long expected2 = total2;
              @SuppressWarnings("boxing")
              final Long actual2 = sum(n1, n2, n3, n4, n5, numbers2);
              // System.out.println("expected: " + expected2 + "\nactual:   " + actual2);
              assertThat(actual2, is(equalTo(expected2)));
            }
          }
        }
      }
    }

    final long[] numbers3 = new long[NUMBERS3.length];
    System.arraycopy(NUMBERS3, 0, numbers3, 0, NUMBERS3.length);
    final long[] numbers4 = new long[NUMBERS4.length];
    System.arraycopy(NUMBERS4, 0, numbers4, 0, NUMBERS4.length);

    for (final long n1 : numbers3) {
      for (final long n2 : numbers4) {
        for (final long n3 : numbers3) {
          for (final long n4 : numbers4) {
            for (final long n5 : numbers3) {
              long total3 = n1 + n2 + n3 + n4 + n5;
              for (final long n : numbers3) total3 += n;

              @SuppressWarnings("boxing")
              final Long expected3 = total3;
              @SuppressWarnings("boxing")
              final Long actual3 = sum(n1, n2, n3, n4, n5, numbers3);
              // System.out.println("expected: " + expected3 + "\nactual:   " + actual3);
              assertThat(actual3, is(equalTo(expected3)));

              long total4 = n1 + n2 + n3 + n4 + n5;
              for (final long n : numbers4) total4 += n;

              @SuppressWarnings("boxing")
              final Long expected4 = total4;
              @SuppressWarnings("boxing")
              final Long actual4 = sum(n1, n2, n3, n4, n5, numbers4);
              // System.out.println("expected: " + expected4 + "\nactual:   " + actual4);
              assertThat(actual4, is(equalTo(expected4)));
            }
          }
        }
      }
    }
  }
예제 #3
0
 @Configuration
 public Option[] config() {
   return options(
       junitBundles(),
       systemProperty("org.ops4j.pax.url.mvn.localRepository")
           .value(System.getProperty("maven.repo.local")),
       mavenBundle("org.jruby", "jruby-complete", System.getProperty("jruby.version")),
       mavenBundle("org.jruby.osgi", "gems-bundle", "1.0"),
       mavenBundle("org.jruby.osgi", "scripts-bundle", "1.0"));
 }
 @Test
 public void get_A$String() throws Exception {
   MemcachedSessionStore store = new MemcachedSessionStore(getMemcached());
   // given
   String key = "MemcachedSessionStoreTest#get_A$String_" + System.currentTimeMillis();
   String value = "cached" + System.currentTimeMillis();
   store.set(key, 60, value);
   // when
   String actual = store.get(key);
   // then
   assertThat(actual, is(equalTo(value)));
 }
예제 #5
0
  // --- NBHMLFeeder ---
  // Class to be called from another thread, to get concurrent installs into
  // the table.
  private static class NBHMLFeeder implements Callable<Object> {
    private static final Random _rand = new Random(System.currentTimeMillis());
    private final NonBlockingIdentityHashMap<Long, TestKey> _map;
    private final int _count;
    private final CyclicBarrier _barrier;
    private final long _offset;

    public NBHMLFeeder(
        final NonBlockingIdentityHashMap<Long, TestKey> map,
        final int count,
        final CyclicBarrier barrier,
        final long offset) {
      _map = map;
      _count = count;
      _barrier = barrier;
      _offset = offset;
    }

    public Object call() throws Exception {
      _barrier.await(); // barrier, to force racing start
      for (long j = 0; j < _count; j++)
        _map.put(
            j + _offset,
            new TestKey(_rand.nextLong(), _rand.nextInt(), (short) _rand.nextInt(Short.MAX_VALUE)));
      return null;
    }
  }
예제 #6
0
 void work_helper(
     NonBlockingIdentityHashMap<String, String> nbhm, String thrd, int d, String[] keys) {
   final int ITERS = 20000;
   for (int j = 0; j < 10; j++) {
     long start = System.nanoTime();
     for (int i = d; i < ITERS; i += 2)
       assertThat(
           "this key not in there, so putIfAbsent must work",
           nbhm.putIfAbsent(keys[i], thrd),
           is((String) null));
     for (int i = d; i < ITERS; i += 2) assertTrue(nbhm.remove(keys[i], thrd));
     double delta_nanos = System.nanoTime() - start;
     double delta_secs = delta_nanos / 1000000000.0;
     double ops = ITERS * 2;
     // System.out.println("Thrd"+thrd+" "+(ops/delta_secs)+" ops/sec size="+nbhm.size());
   }
 }
 @Test
 public void basicSanityFromResourceReader() throws Exception {
   InputStream is = UnicodeBomInputStreamTest.class.getResourceAsStream("bom.js");
   UnicodeBomInputStream is2 = new UnicodeBomInputStream(is);
   is2.skipBOM();
   InputStreamReader isr = new InputStreamReader(is2, Charset.forName("UTF-8"));
   String s = Util.readerToString(isr);
   String nl = System.getProperty("line.separator");
   assertThat(s, is("// This file starts with a UTF-8 BOM." + nl + "alert(\"Hello BOM\");" + nl));
 }
예제 #8
0
 @Test
 public void writeList2() throws Exception {
   VType vType = ValueFactory.toVType(Arrays.asList("A", "B", "C", "D", "E"));
   StringWriter writer = new StringWriter();
   TextIO.writeList(vType, writer);
   writer.flush();
   assertThat(
       writer.toString(),
       equalTo(
           "A"
               + System.lineSeparator()
               + "B"
               + System.lineSeparator()
               + "C"
               + System.lineSeparator()
               + "D"
               + System.lineSeparator()
               + "E"
               + System.lineSeparator()));
 }
 static {
   String projectId = System.getenv(TEST_PROJECT_ID_ENV);
   if (projectId == null) {
     PROJECT_ID = DEFAULT_TEST_PROJECT_ID;
   } else {
     PROJECT_ID = projectId;
   }
   UUID uuid = UUID.randomUUID();
   // The '=@~' part is for checking the descrepancy of base64
   // variants used on the server side and on the client side.
   MESSAGE = "=@~test-message-" + uuid;
 }
 @Test
 public void remove_A$String() throws Exception {
   MemcachedSessionStore store = new MemcachedSessionStore(getMemcached());
   // given
   String key = "MemcachedSessionStoreTest#remove_A$String_" + System.currentTimeMillis();
   // when
   store.set(key, 60, "aaa");
   store.remove(key);
   String actual = store.get(key);
   // then
   assertThat(actual, is(nullValue()));
 }
 @Test
 public void set_A$String$int$Object_Expire() throws Exception {
   MemcachedSessionStore store = new MemcachedSessionStore(getMemcached());
   // given
   String key = "MemcachedSessionStoreTest#set_A$String$int$Object_" + System.currentTimeMillis();
   int expire = 2;
   String value = "aaa";
   // when
   store.set(key, expire, value);
   Thread.sleep(3000L);
   String actual = store.get(key);
   // then
   assertThat(actual, is(nullValue()));
 }
  @Test
  public void testLongProfiling() throws Exception {

    Logger logger = Logger.getLogger(getClass());
    MDC.put(GelfUtil.MDC_REQUEST_START_MS, "" + (System.currentTimeMillis() - 2000));

    logger.info(LOG_MESSAGE);
    assertEquals(1, GelfTestSender.getMessages().size());

    GelfMessage gelfMessage = GelfTestSender.getMessages().get(0);

    assertNotNull(gelfMessage.getField(GelfUtil.MDC_REQUEST_DURATION));
    assertNotNull(gelfMessage.getField(GelfUtil.MDC_REQUEST_END));
  }
예제 #13
0
  // @Test  TODO. commented out. Can't get test to work without an application server.
  public void testCreateSql2oFromJndi() throws Exception {
    System.setProperty(
        Context.INITIAL_CONTEXT_FACTORY, "org.apache.naming.java.javaURLContextFactory");
    System.setProperty(Context.URL_PKG_PREFIXES, "org.apache.naming");

    InitialContext ic = new InitialContext();

    ic.createSubcontext("java:");
    ic.createSubcontext("java:comp");
    ic.createSubcontext("java:comp/env");

    JDBCDataSource datasource = new JDBCDataSource();
    datasource.setUrl(url);
    datasource.setUser(user);
    datasource.setPassword(pass);

    ic.bind("java:comp/env/Sql2o", datasource);

    System.out.println("Datasource initialized.");

    Sql2o jndiSql2o = new Sql2o("Sql2o");

    assertTrue(jndiSql2o != null);
  }
  @Test
  public void retrieveCalendar() throws Exception {
    final String calendarName = "weekdayCalendar";
    Calendar calendar = getCalendar();
    jobStore.storeCalendar(calendarName, calendar, false, false);

    Calendar retrievedCalendar = jobStore.retrieveCalendar(calendarName);

    assertEquals(calendar.getClass(), retrievedCalendar.getClass());
    assertEquals(calendar.getDescription(), retrievedCalendar.getDescription());
    long currentTime = System.currentTimeMillis();
    assertEquals(
        calendar.getNextIncludedTime(currentTime),
        retrievedCalendar.getNextIncludedTime(currentTime));
  }
예제 #15
0
  @Test
  public void testZipFileWrite() throws Exception {

    String outputFileName = null;

    try {
      // Get somewhere temporary to write out to
      outputFileName = File.createTempFile("ItemWriterTest-", ".csv.zip").getAbsolutePath();

      // Configure the ItemWriter
      C24ItemWriter itemWriter = new C24ItemWriter();
      itemWriter.setSink(new TextualSink());
      itemWriter.setWriterSource(new ZipFileWriterSource());
      itemWriter.setup(getStepExecution(outputFileName));
      // Write the employees out
      itemWriter.write(employees);
      // Close the file
      itemWriter.cleanup();

      // Check that we wrote out what was expected
      ZipFile zipFile = new ZipFile(outputFileName);
      Enumeration<? extends ZipEntry> entries = zipFile.entries();
      assertNotNull(entries);
      // Make sure there's at least one entry
      assertTrue(entries.hasMoreElements());
      ZipEntry entry = entries.nextElement();
      // Make sure that the trailing .zip has been removed and the leading path has been removed
      assertFalse(entry.getName().contains(System.getProperty("file.separator")));
      assertFalse(entry.getName().endsWith(".zip"));
      // Make sure that there aren't any other entries
      assertFalse(entries.hasMoreElements());

      try {
        compareCsv(zipFile.getInputStream(entry), employees);
      } finally {
        if (zipFile != null) {
          zipFile.close();
        }
      }

    } finally {
      if (outputFileName != null) {
        // Clear up our temporary file
        File file = new File(outputFileName);
        file.delete();
      }
    }
  }
@Category(EventDependent.class)
public class StoreFileThenUploadThenDownloadAndVerifyInTrackingReportTest
    extends AbstractTrackingReportTest {
  final byte[] bytes = ("This is a test: " + System.nanoTime()).getBytes();
  final String path = "/path/to/foo.class";

  @Before
  public void prepareStore() throws Exception {
    HostedRepository r = new HostedRepository(STORE);
    r = client.stores().create(r, "adding test hosted", HostedRepository.class);
  }

  @Test
  public void runUploadThenDownload() throws Exception {
    final String trackingId = newName();

    IndyFoloContentClientModule module = client.module(IndyFoloContentClientModule.class);

    // upload
    module.store(trackingId, hosted, STORE, path, new ByteArrayInputStream(bytes));

    // download
    module.get(trackingId, hosted, STORE, path);

    Thread.sleep(2000); // wait for event being fired

    sealAndCheck(trackingId);
  }

  void sealAndCheck(String trackingId) throws IndyClientException {
    // seal
    IndyFoloAdminClientModule adminModule = client.module(IndyFoloAdminClientModule.class);
    boolean success = adminModule.sealTrackingRecord(trackingId);
    assertThat(success, equalTo(true));

    // check report
    final TrackedContentDTO report = adminModule.getTrackingReport(trackingId);
    assertThat(report, notNullValue());

    final Set<TrackedContentEntryDTO> downloads = report.getDownloads();
    assertThat(downloads, notNullValue());
    assertThat(downloads.size(), equalTo(1));

    final Set<TrackedContentEntryDTO> uploads = report.getUploads();
    assertThat(uploads, notNullValue());
    assertThat(uploads.size(), equalTo(1));
  }
}
  @Before
  public void setup() throws IOException {
    CouchConfig config = super.getCouchConfig(CLOUDANT_TEST_DB_NAME + System.currentTimeMillis());
    remoteDb =
        new CouchClientWrapper(
            config.getRootUri(), config.getRequestInterceptors(), config.getResponseInterceptors());
    bodyOne =
        DocumentBodyFactory.create(
            FileUtils.readFileToByteArray(TestUtils.loadFixture(documentOneFile)));
    bodyTwo =
        DocumentBodyFactory.create(
            FileUtils.readFileToByteArray(TestUtils.loadFixture(documentTwoFile)));

    CouchClientWrapperDbUtils.deleteDbQuietly(remoteDb);
    remoteDb.createDatabase();
  }
예제 #18
0
  @Test
  public void test1create() throws InterruptedException {
    long now = System.currentTimeMillis();

    Thread.sleep(20);

    String token = store.newToken("*****@*****.**", "domain.com");

    assertThat(token, is(notNullValue()));
    assertThat(token.length(), is(not(0)));
    assertThat(store.getSessions().size(), is(1));

    Session s = store.getSessions().get(0);

    assertThat(s.getId(), is(notNullValue()));
    assertThat(s.getDomain(), is("domain.com"));
    assertThat(s.getToken(), is(token));
    assertThat(s.getUser(), is("*****@*****.**"));
    assertThat(s.getSessionStart(), is(greaterThan(now)));
    assertThat(s.getSessionExpiration(), is(greaterThan(s.getSessionStart())));
  }
예제 #19
0
  public IsisSessionDefault(
      final IsisSessionFactory sessionFactory,
      final AuthenticationSession authenticationSession,
      final PersistenceSession persistenceSession) {

    // global context
    ensureThatArg(sessionFactory, is(not(nullValue())), "execution context factory is required");

    // session
    ensureThatArg(
        authenticationSession, is(not(nullValue())), "authentication session is required");
    ensureThatArg(persistenceSession, is(not(nullValue())), "persistence session is required");

    this.isisSessionFactory = sessionFactory;

    this.authenticationSession = authenticationSession;
    this.persistenceSession = persistenceSession;

    setSessionOpenTime(System.currentTimeMillis());

    this.id = nextId++;
  }
예제 #20
0
파일: LFT.java 프로젝트: qarocks/SPW
  @Before
  public void setUp() throws Exception {

    // System.setProperty("webdriver.chrome.driver","C:\\Users\\Sneha\\AppData\\Local\\Google\\Chrome\\Application\\chrome.exe");
    System.setProperty("webdriver.firefox.bin", "C:\\Mozilla Firefox\\firefox.exe");

    /*File profileDir = new File("C:\\Users\\Sneha\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\hl4nsrj3.no silveright");
        FirefoxProfile profile = new FirefoxProfile(profileDir);
        profile.setPreference("general.useragent.override", "same user agent string as above");


    driver = new FirefoxDriver(profile);
    */
    driver = new FirefoxDriver();
    // driver=new ChromeDriver();

    // WebDriver driver = new InternetExplorerDriver();

    driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
    selenium = new WebDriverBackedSelenium(driver, baseUrl);

    webDriver = new HtmlUnitDriver(true);
  }
예제 #21
0
 @Test
 public void writeList1() throws Exception {
   VType vType = ValueFactory.toVType(new ArrayDouble(10, 8, 6, 4, 2, 0));
   StringWriter writer = new StringWriter();
   TextIO.writeList(vType, writer);
   writer.flush();
   assertThat(
       writer.toString(),
       equalTo(
           "10.0"
               + System.lineSeparator()
               + "8.0"
               + System.lineSeparator()
               + "6.0"
               + System.lineSeparator()
               + "4.0"
               + System.lineSeparator()
               + "2.0"
               + System.lineSeparator()
               + "0.0"
               + System.lineSeparator()));
 }
예제 #22
0
 @Test
 public void joinで文字列が連結される() throws Exception {
   String ls = System.getProperty("line.separator");
   String expected = "Hello" + ls + "World" + ls;
   assertThat(MultiLineString.join("Hello", "World"), is(text(expected)));
 }
예제 #23
0
 public static Matcher<String> text(String text) {
   return new MultiLineStringMatcher(text, System.getProperty("line.separator"));
 }
예제 #24
0
 public JWTStoreTest() {
   System.setProperty("jwt.hmacSharedSecret", "qrllxoyy2x2bnsp84yjoi5wujrnqun6y0lspeu28");
   this.store = JWTStore.getInstance();
 }