예제 #1
1
  @Test
  public void test_2GB_over() throws IOException {
    Assume.assumeTrue(CC.FULL_TEST);

    byte[] data = new byte[51111];
    int dataHash = Arrays.hashCode(data);

    Set<Long> recids = new TreeSet<Long>();

    for (int i = 0; i < 1e5; i++) {
      long recid = engine.recordPut(data, Serializer.BYTE_ARRAY_SERIALIZER);
      recids.add(recid);

      //            if(i%10000==0){
      //            System.out.println(recid);
      //            for(Long l:recids){
      //                byte[] b = engine.recordGet(l, Serializer.BYTE_ARRAY_SERIALIZER);
      //                int hash = Arrays.hashCode(b);
      //                assertEquals(l,dataHash, hash);
      //            }
      //            }

    }

    engine.commit();

    for (Long l : recids) {
      byte[] b = engine.recordGet(l, Serializer.BYTE_ARRAY_SERIALIZER);
      int hash = Arrays.hashCode(b);
      assertEquals(dataHash, hash);
    }
  }
예제 #2
1
 @Test
 public void testPutRemoveGet() {
   Map<Integer, Integer> myMap = new MyMap<>();
   Map<Integer, Integer> control = new HashMap<>();
   for (int i = 0; i < N; i++) {
     int k = random.nextInt();
     int v = random.nextInt();
     myMap.put(k, v);
     control.put(k, v);
   }
   Set<Integer> keysToRemove = new HashSet<>();
   for (int k : control.keySet()) {
     if (random.nextBoolean()) {
       keysToRemove.add(k);
     }
   }
   for (int k : keysToRemove) {
     control.remove(k);
     myMap.remove(k);
   }
   assertEquals(myMap.size(), control.size());
   for (int k : control.keySet()) {
     assertEquals(myMap.get(k), control.get(k));
     int r = random.nextInt();
     assertEquals(myMap.get(r), control.get(r));
   }
 }
예제 #3
0
 /** Test of elementExists method, of class Set. */
 @Test
 public void testElementExists() {
   Set<Integer> set = new Set<Integer>();
   assertFalse(set.elementExists(1));
   set.addElement(1);
   assertTrue(set.elementExists(1));
 }
예제 #4
0
 /** Test of isEmpty method, of class Set. */
 @Test
 public void testIsEmpty() {
   Set<Integer> set = new Set<Integer>();
   assertTrue(set.isEmpty());
   set.addElement(0);
   assertFalse(set.isEmpty());
 }
예제 #5
0
  @Test
  public void testCompactionLog() throws Exception {
    SystemKeyspace.discardCompactionsInProgress();

    String cf = "Standard4";
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(cf);
    SchemaLoader.insertData(KEYSPACE1, cf, 0, 1);
    cfs.forceBlockingFlush();

    Collection<SSTableReader> sstables = cfs.getSSTables();
    assertFalse(sstables.isEmpty());
    Set<Integer> generations =
        Sets.newHashSet(
            Iterables.transform(
                sstables,
                new Function<SSTableReader, Integer>() {
                  public Integer apply(SSTableReader sstable) {
                    return sstable.descriptor.generation;
                  }
                }));
    UUID taskId = SystemKeyspace.startCompaction(cfs, sstables);
    Map<Pair<String, String>, Map<Integer, UUID>> compactionLogs =
        SystemKeyspace.getUnfinishedCompactions();
    Set<Integer> unfinishedCompactions = compactionLogs.get(Pair.create(KEYSPACE1, cf)).keySet();
    assertTrue(unfinishedCompactions.containsAll(generations));

    SystemKeyspace.finishCompaction(taskId);
    compactionLogs = SystemKeyspace.getUnfinishedCompactions();
    assertFalse(compactionLogs.containsKey(Pair.create(KEYSPACE1, cf)));
  }
예제 #6
0
  @Test
  public void testFlatMapMaxConcurrent() {
    final int m = 4;
    final AtomicInteger subscriptionCount = new AtomicInteger();
    Observable<Integer> source =
        Observable.range(1, 10)
            .flatMap(
                new Func1<Integer, Observable<Integer>>() {
                  @Override
                  public Observable<Integer> call(Integer t1) {
                    return compose(Observable.range(t1 * 10, 2), subscriptionCount, m)
                        .subscribeOn(Schedulers.computation());
                  }
                },
                m);

    TestSubscriber<Integer> ts = new TestSubscriber<Integer>();

    source.subscribe(ts);

    ts.awaitTerminalEvent();
    ts.assertNoErrors();
    Set<Integer> expected =
        new HashSet<Integer>(
            Arrays.asList(
                10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 60, 61, 70, 71, 80, 81, 90, 91, 100, 101));
    Assert.assertEquals(expected.size(), ts.getOnNextEvents().size());
    Assert.assertTrue(expected.containsAll(ts.getOnNextEvents()));
  }
  /**
   * Test usage from multiple threads.
   *
   * @throws InterruptedException if interrupted
   */
  public final void testInstancesUsedFromMultipleThreads() throws InterruptedException {
    final Set<Touchable> set = Collections.synchronizedSet(new HashSet<Touchable>());
    final List<Touchable> list = Collections.synchronizedList(new ArrayList<Touchable>());
    final ComponentAdapter componentAdapter =
        new ThreadLocalizing.ThreadLocalized(
            new ConstructorInjection.ConstructorInjector(
                Touchable.class, SimpleTouchable.class, null));
    final Touchable touchable =
        (Touchable) componentAdapter.getComponentInstance(null, ComponentAdapter.NOTHING.class);

    final Thread[] threads = {
      new Thread(new Runner(touchable, list, set), "junit-1"),
      new Thread(new Runner(touchable, list, set), "junit-2"),
      new Thread(new Runner(touchable, list, set), "junit-3"),
    };
    for (int i = threads.length; i-- > 0; ) {
      threads[i].start();
    }
    Thread.sleep(300);
    for (int i = threads.length; i-- > 0; ) {
      synchronized (threads[i]) {
        threads[i].notifyAll();
      }
    }
    Thread.sleep(300);
    for (int i = threads.length; i-- > 0; ) {
      threads[i].interrupt();
    }
    Thread.sleep(300);
    assertEquals(6, list.size());
    assertEquals(3, set.size());
  }
 @Test
 public void iterateOverMapEntries() {
   HazelcastClient hClient = getHazelcastClient();
   IMap<String, String> map = hClient.getMap("iterateOverMapEntries");
   map.put("1", "A");
   map.put("2", "B");
   map.put("3", "C");
   Set<Entry<String, String>> entrySet = map.entrySet();
   assertEquals(3, entrySet.size());
   Set<String> keySet = map.keySet();
   for (Entry<String, String> entry : entrySet) {
     assertTrue(keySet.contains(entry.getKey()));
     assertEquals(entry.getValue(), map.get(entry.getKey()));
   }
   Iterator<Entry<String, String>> it = entrySet.iterator();
   for (String key : keySet) {
     MapEntry mapEntry = map.getMapEntry(key);
     assertEquals(1, mapEntry.getHits());
   }
   while (it.hasNext()) {
     it.next();
     it.remove();
   }
   assertTrue(map.isEmpty());
 }
예제 #9
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);
  }
 public void doFunctionalQueryTest(IMap imap) {
   Employee em = new Employee("joe", 33, false, 14.56);
   imap.put("1", new Employee("joe", 33, false, 14.56));
   imap.put("2", new Employee("ali", 23, true, 15.00));
   for (int i = 3; i < 103; i++) {
     imap.put(
         String.valueOf(i), new Employee("name" + i, i % 60, ((i % 2) == 1), Double.valueOf(i)));
   }
   Set<Map.Entry> entries = imap.entrySet();
   assertEquals(102, entries.size());
   int itCount = 0;
   for (Map.Entry entry : entries) {
     Employee c = (Employee) entry.getValue();
     itCount++;
   }
   assertEquals(102, itCount);
   EntryObject e = new PredicateBuilder().getEntryObject();
   Predicate predicate = e.is("active").and(e.get("age").equal(23));
   entries = imap.entrySet(predicate);
   assertEquals(3, entries.size());
   for (Map.Entry entry : entries) {
     Employee c = (Employee) entry.getValue();
     assertEquals(c.getAge(), 23);
     assertTrue(c.isActive());
   }
   imap.remove("2");
   entries = imap.entrySet(predicate);
   assertEquals(2, entries.size());
   for (Map.Entry entry : entries) {
     Employee c = (Employee) entry.getValue();
     assertEquals(c.getAge(), 23);
     assertTrue(c.isActive());
   }
 }
예제 #11
0
  private static void assertDeepChildrenEquals(SNode expectedNode, SNode actualNode) {
    Set<String> roles = new HashSet<String>();
    for (SNode child : expectedNode.getChildren()) {
      roles.add(child.getRoleInParent());
    }
    for (SNode child : actualNode.getChildren()) {
      roles.add(child.getRoleInParent());
    }

    for (String role : roles) {
      Iterable<? extends SNode> expectedChildren = expectedNode.getChildren(role);
      Iterable<? extends SNode> actualChildren = actualNode.getChildren(role);

      int esize = IterableUtil.asCollection(expectedChildren).size();
      int asize = IterableUtil.asCollection(actualChildren).size();
      assertEquals(
          getErrorString("child count in role " + role, expectedNode, actualNode), esize, asize);

      Iterator<? extends SNode> actualIterator = actualChildren.iterator();
      for (SNode expectedChild : expectedChildren) {
        SNode actualChild = actualIterator.next();
        assertEquals(
            getErrorString("children in role " + role, expectedNode, actualNode),
            expectedChild.getNodeId(),
            actualChild.getNodeId());
        assertDeepNodeEquals(expectedChild, actualChild);
      }
    }
  }
예제 #12
0
  // FIXME: fails!  needs MarcCombiningReader for mhld or at least a diff version of RawRecordReader
  @Test
  public void testMultMHLDsWithSameID() throws IOException {
    // bib134, multMhlds1
    String bibFilePath = testDataParentPath + File.separator + "mhldMergeBibs134.mrc";
    String mhldFilePath = testDataParentPath + File.separator + "mhldMergeMhlds1Mult.mrc";
    Map<String, Record> mergedRecs =
        MergeSummaryHoldings.mergeMhldsIntoBibRecordsAsMap(bibFilePath, mhldFilePath);

    Record mergedRec = mergedRecs.get("a1");
    assertEquals("Expected three 852", 3, mergedRec.getVariableFields("852").size());
    Set<String> expectedVals = new HashSet<String>();
    expectedVals.add("Location1");
    expectedVals.add("Location2");
    RecordTestingUtils.assertSubfieldHasExpectedValues(mergedRec, "852", 'b', expectedVals);

    expectedVals.clear();
    expectedVals.add("(month)");
    expectedVals.add("(season)");
    RecordTestingUtils.assertSubfieldHasExpectedValues(mergedRec, "853", 'b', expectedVals);

    assertEquals("Expected one 863", 2, mergedRec.getVariableFields("863").size());
    assertEquals("Expected one 866", 1, mergedRec.getVariableFields("866").size());
    // fail("Implement me");
    System.out.println("Test testMultMHLDsWithSameID() successful");
  }
예제 #13
0
  @Test
  public void scanTest() {
    Map<String, Map<String, ByteIterator>> keyMap = new HashMap<>();
    for (int i = 0; i < 5; i++) {
      String insertKey = KEY_PREFIX + i;
      keyMap.put(insertKey, insertRow(insertKey));
    }

    Set<String> fieldSet = new HashSet<>();
    fieldSet.add("FIELD0");
    fieldSet.add("FIELD1");
    int startIndex = 1;
    int resultRows = 3;

    Vector<HashMap<String, ByteIterator>> resultVector = new Vector<>();
    orientDBClient.scan(CLASS, KEY_PREFIX + startIndex, resultRows, fieldSet, resultVector);

    // Check the resultVector is the correct size
    assertEquals(
        "Assert the correct number of results rows were returned", resultRows, resultVector.size());
    // Check each vector row to make sure we have the correct fields
    int testIndex = startIndex;
    for (HashMap<String, ByteIterator> result : resultVector) {
      assertEquals(
          "Assert that this row has the correct number of fields", fieldSet.size(), result.size());
      for (String field : fieldSet) {
        assertEquals(
            "Assert this field is correct in this row",
            keyMap.get(KEY_PREFIX + testIndex).get(field).toString(),
            result.get(field).toString());
      }
      testIndex++;
    }
  }
예제 #14
0
  private List<String> executeDDL(
      String ddlFileName,
      @Nullable String dataFileName,
      boolean isLocalTable,
      @Nullable String[] args)
      throws Exception {

    Path ddlFilePath = new Path(currentQueryPath, ddlFileName);
    FileSystem fs = ddlFilePath.getFileSystem(conf);
    assertTrue(ddlFilePath + " existence check", fs.exists(ddlFilePath));

    String template = FileUtil.readTextFile(new File(ddlFilePath.toUri()));
    String dataFilePath = null;
    if (dataFileName != null) {
      dataFilePath = getDataSetFile(dataFileName).toString();
    }
    String compiled = compileTemplate(template, dataFilePath, args);

    List<ParsedResult> parsedResults = SimpleParser.parseScript(compiled);
    List<String> createdTableNames = new ArrayList<String>();

    for (ParsedResult parsedResult : parsedResults) {
      // parse a statement
      Expr expr = sqlParser.parse(parsedResult.getStatement());
      assertNotNull(ddlFilePath + " cannot be parsed", expr);

      if (expr.getType() == OpType.CreateTable) {
        CreateTable createTable = (CreateTable) expr;
        String tableName = createTable.getTableName();
        assertTrue("Table creation is failed.", client.updateQuery(parsedResult.getStatement()));
        TableDesc createdTable = client.getTableDesc(tableName);
        String createdTableName = createdTable.getName();

        assertTrue(
            "table '" + createdTableName + "' creation check", client.existTable(createdTableName));
        if (isLocalTable) {
          createdTableGlobalSet.add(createdTableName);
          createdTableNames.add(tableName);
        }
      } else if (expr.getType() == OpType.DropTable) {
        DropTable dropTable = (DropTable) expr;
        String tableName = dropTable.getTableName();
        assertTrue(
            "table '" + tableName + "' existence check",
            client.existTable(CatalogUtil.buildFQName(currentDatabase, tableName)));
        assertTrue("table drop is failed.", client.updateQuery(parsedResult.getStatement()));
        assertFalse(
            "table '" + tableName + "' dropped check",
            client.existTable(CatalogUtil.buildFQName(currentDatabase, tableName)));
        if (isLocalTable) {
          createdTableGlobalSet.remove(tableName);
        }
      } else {
        assertTrue(ddlFilePath + " is not a Create or Drop Table statement", false);
      }
    }

    return createdTableNames;
  }
예제 #15
0
 @Test
 public void testAllSearchableAttributeCodes() {
   Set<String> codes = attributeService.getAllSearchableAttributeCodes();
   assertNotNull(codes);
   assertFalse(codes.isEmpty());
   Map<String, I18NModel> map = attributeService.getAttributeNamesByCodes(codes);
   assertNotNull(map);
 }
  @Test
  public void testHash() {
    Set<Integer> set = new HashSet<Integer>();
    for (WordNgram w : myNgrams) {
      set.add(w.hashCode());
    }

    assertTrue("hash code test", set.size() > 8);
  }
예제 #17
0
 public void workerSetTest() {
   Set<Worker> workerSet = new HashSet<Worker>();
   Worker worker1 = new Worker("张三", 18);
   worker1.setWorkerId(1);
   workerSet.add(worker1);
   Worker worker2 = new Worker("李四", 8);
   worker2.setWorkerId(2);
   System.out.println(workerSet.contains(worker2));
 }
예제 #18
0
 /** Test of addElement method, of class Set. */
 @Test
 public void testAddElement() {
   Set<String> set = new Set<String>();
   set.addElement("m");
   set.addElement("h");
   set.addElement("m");
   assertTrue(set.elementExists("m"));
   assertFalse(set.elementExists("n"));
 }
예제 #19
0
 /** Test of deleteElement method, of class Set. */
 @Test(expected = ElementNotFoundException.class)
 public void testDeleteElement() throws Exception {
   Set<Integer> set = new Set<Integer>();
   set.deleteElement(3);
   set.addElement(1);
   set.addElement(4);
   set.deleteElement(1);
   assertFalse(set.elementExists(1));
 }
예제 #20
0
 // Check all iterators for correct size counts
 private void checkSizes(int expectedSize) {
   assertEquals("size()", _nbhm.size(), expectedSize);
   Collection<String> vals = _nbhm.values();
   checkSizes("values()", vals.size(), vals.iterator(), expectedSize);
   Set<String> keys = _nbhm.keySet();
   checkSizes("keySet()", keys.size(), keys.iterator(), expectedSize);
   Set<Entry<String, String>> ents = _nbhm.entrySet();
   checkSizes("entrySet()", ents.size(), ents.iterator(), expectedSize);
 }
 @Test
 public void testInstance() {
   assertNotNull(instance);
   final Set<Member> members = instance.getCluster().getMembers();
   assertEquals(1, members.size());
   final Member member = members.iterator().next();
   final InetSocketAddress inetSocketAddress = member.getInetSocketAddress();
   assertEquals(5700, inetSocketAddress.getPort());
   assertEquals("test-instance", config.getInstanceName());
   assertEquals("HAZELCAST_ENTERPRISE_LICENSE_KEY", config.getLicenseKey());
 }
  // Failing test due to equals() contract violation
  @Test
  public void testCollectionEquals() {
    Set<String> p = new HashSet<String>();
    InstrumentedCollection<String> t = new InstrumentedCollection<String>(p);

    p.add("cat");
    p.add("dog");

    assertTrue(p.equals(t));
    assertTrue(t.equals(p));
  }
예제 #23
0
  @Test
  public void testInit_NonEmptyCollection() throws Exception {

    // Mock
    ConnectionManager connectionManager = mock(ConnectionManager.class);
    Connection connection = mock(Connection.class);
    Connection connection1 = mock(Connection.class);
    Statement statement = mock(Statement.class);
    PreparedStatement preparedStatement = mock(PreparedStatement.class);

    when(connection1.prepareStatement("INSERT OR IGNORE INTO " + TABLE_NAME + " values(?, ?);"))
        .thenReturn(preparedStatement);
    when(connectionManager.getConnection(any(SQLiteIndex.class)))
        .thenReturn(connection)
        .thenReturn(connection1);
    when(connectionManager.isApplyUpdateForIndexEnabled(any(SQLiteIndex.class))).thenReturn(true);
    when(connection.createStatement()).thenReturn(statement);
    when(preparedStatement.executeBatch()).thenReturn(new int[] {2});

    // The objects to add
    Set<Car> initWithObjects = new HashSet<Car>(2);
    initWithObjects.add(
        new Car(1, "Ford", "Focus", Car.Color.BLUE, 5, 9000.50, Arrays.asList("abs", "gps")));
    initWithObjects.add(
        new Car(2, "Honda", "Civic", Car.Color.RED, 5, 5000.00, Arrays.asList("airbags")));

    SQLiteIndex<String, Car, Integer> carFeaturesOffHeapIndex =
        new SQLiteIndex<String, Car, Integer>(
            Car.FEATURES, OBJECT_TO_ID, ID_TO_OBJECT, connectionManager);

    carFeaturesOffHeapIndex.init(initWithObjects, new QueryOptions());

    // Verify
    verify(statement, times(1))
        .executeUpdate(
            "CREATE TABLE IF NOT EXISTS "
                + TABLE_NAME
                + " (objectKey INTEGER, value TEXT, PRIMARY KEY (objectKey, value)) WITHOUT ROWID;");
    verify(statement, times(1))
        .executeUpdate(
            "CREATE INDEX IF NOT EXISTS " + INDEX_NAME + " ON " + TABLE_NAME + " (value);");
    verify(statement, times(2)).close();
    verify(connection, times(1)).close();

    verify(preparedStatement, times(2)).setObject(1, 1);
    verify(preparedStatement, times(1)).setObject(1, 2);
    verify(preparedStatement, times(1)).setObject(2, "abs");
    verify(preparedStatement, times(1)).setObject(2, "gps");
    verify(preparedStatement, times(1)).setObject(2, "airbags");
    verify(preparedStatement, times(3)).addBatch();
    verify(preparedStatement, times(1)).executeBatch();
    verify(preparedStatement, times(1)).close();
    verify(connection1, times(1)).close();
  }
예제 #24
0
  /**
   * Test importing of Clinical Data File.
   *
   * @throws DaoException Database Access Error.
   * @throws IOException IO Error.
   */
  @Test
  @Ignore("To be fixed")
  public void testImportClinicalDataParameters() throws Exception {

    // TBD: change this to use getResourceAsStream()
    File clinicalFile = new File("target/test-classes/clinical_data.txt");
    ImportClinicalData importClinicalData = new ImportClinicalData(study, clinicalFile);
    importClinicalData.importData();

    Set<String> paramSet = DaoClinicalData.getDistinctParameters(study.getInternalId());
    assertEquals(9, paramSet.size());
  }
  @Test
  public void userServiceReturnsExpectedData() throws Exception {
    setContext(
        "<ldap-user-service id='ldapUDS' user-search-filter='(uid={0})' group-search-filter='member={0}' /><ldap-server ldif='classpath:test-server.ldif'/>");

    UserDetailsService uds = (UserDetailsService) appCtx.getBean("ldapUDS");
    UserDetails ben = uds.loadUserByUsername("ben");

    Set<String> authorities = AuthorityUtils.authorityListToSet(ben.getAuthorities());
    assertEquals(3, authorities.size());
    assertTrue(authorities.contains("ROLE_DEVELOPERS"));
  }
  @Test
  public void testRemoveService() {
    ServiceHolder tested = new ServiceHolder();
    Object service = new Object();

    // Get the hash set.
    Set<Object> servicesSet = getField(tested, Set.class);
    servicesSet.add(service);

    tested.removeService(service);

    assertTrue("Set should be empty after removeal.", servicesSet.isEmpty());
  }
예제 #27
0
  @Test
  public void testNotifyObjectsRemoved() throws Exception {

    // Mock
    ConnectionManager connectionManager = mock(ConnectionManager.class);
    Connection connection = mock(Connection.class);
    Connection connection1 = mock(Connection.class);
    Statement statement = mock(Statement.class);
    PreparedStatement preparedStatement = mock(PreparedStatement.class);

    // Behaviour
    when(connectionManager.getConnection(any(SQLiteIndex.class)))
        .thenReturn(connection)
        .thenReturn(connection1);
    when(connectionManager.isApplyUpdateForIndexEnabled(any(SQLiteIndex.class))).thenReturn(true);
    when(connection.createStatement()).thenReturn(statement);
    when(connection1.prepareStatement("DELETE FROM " + TABLE_NAME + " WHERE objectKey = ?;"))
        .thenReturn(preparedStatement);
    when(preparedStatement.executeBatch()).thenReturn(new int[] {1});

    // The objects to add
    Set<Car> removedObjects = new HashSet<Car>(2);
    removedObjects.add(
        new Car(1, "Ford", "Focus", Car.Color.BLUE, 5, 9000.50, Arrays.asList("abs", "gps")));
    removedObjects.add(
        new Car(2, "Honda", "Civic", Car.Color.RED, 5, 5000.00, Arrays.asList("airbags")));

    @SuppressWarnings({"unchecked", "unused"})
    SQLiteIndex<String, Car, Integer> carFeaturesOffHeapIndex =
        new SQLiteIndex<String, Car, Integer>(
            Car.FEATURES, OBJECT_TO_ID, ID_TO_OBJECT, connectionManager);

    carFeaturesOffHeapIndex.removeAll(removedObjects, new QueryOptions());

    // Verify
    verify(statement, times(1))
        .executeUpdate(
            "CREATE TABLE IF NOT EXISTS "
                + TABLE_NAME
                + " (objectKey INTEGER, value TEXT, PRIMARY KEY (objectKey, value)) WITHOUT ROWID;");
    verify(statement, times(1))
        .executeUpdate(
            "CREATE INDEX IF NOT EXISTS " + INDEX_NAME + " ON " + TABLE_NAME + " (value);");
    verify(connection, times(1)).close();

    verify(preparedStatement, times(1)).setObject(1, 1);
    verify(preparedStatement, times(1)).setObject(1, 2);
    verify(preparedStatement, times(2)).addBatch();
    verify(preparedStatement, times(1)).executeBatch();
    verify(connection1, times(1)).close();
  }
예제 #28
0
  @Test
  public void testCreateAndDropTable() throws Exception {
    catalog.createDatabase("tmpdb1", TajoConstants.DEFAULT_TABLESPACE_NAME);
    assertTrue(catalog.existDatabase("tmpdb1"));
    catalog.createDatabase("tmpdb2", TajoConstants.DEFAULT_TABLESPACE_NAME);
    assertTrue(catalog.existDatabase("tmpdb2"));

    TableDesc table1 = createMockupTable("tmpdb1", "table1");
    catalog.createTable(table1);

    TableDesc table2 = createMockupTable("tmpdb2", "table2");
    catalog.createTable(table2);

    Set<String> tmpdb1 = Sets.newHashSet(catalog.getAllTableNames("tmpdb1"));
    assertEquals(1, tmpdb1.size());
    assertTrue(tmpdb1.contains("table1"));

    Set<String> tmpdb2 = Sets.newHashSet(catalog.getAllTableNames("tmpdb2"));
    assertEquals(1, tmpdb2.size());
    assertTrue(tmpdb2.contains("table2"));

    catalog.dropDatabase("tmpdb1");
    assertFalse(catalog.existDatabase("tmpdb1"));

    tmpdb2 = Sets.newHashSet(catalog.getAllTableNames("tmpdb2"));
    assertEquals(1, tmpdb2.size());
    assertTrue(tmpdb2.contains("table2"));

    catalog.dropDatabase("tmpdb2");
    assertFalse(catalog.existDatabase("tmpdb2"));
  }
 @Test
 public void testMultiMapKeySet() {
   HazelcastClient hClient = getHazelcastClient();
   MultiMap<String, String> map = hClient.getMultiMap("testMultiMapKeySet");
   map.put("Hello", "World");
   map.put("Hello", "Europe");
   map.put("Hello", "America");
   map.put("Hello", "Asia");
   map.put("Hello", "Africa");
   map.put("Hello", "Antarctica");
   map.put("Hello", "Australia");
   Set<String> keys = map.keySet();
   assertEquals(1, keys.size());
 }
예제 #30
0
  @Test
  public void testQueryParams() {

    Map<String, String[]> params = new HashMap<>();
    params.put("sort", new String[] {"asc"});
    params.put("items", new String[] {"10"});

    when(servletRequest.getParameterMap()).thenReturn(params);

    Set<String> result = request.queryParams();

    assertArrayEquals(
        "Should return the query parameter names", params.keySet().toArray(), result.toArray());
  }