/** * Gets a new time uuid using {@link ClockResolution#createClock()} as a time generator. * It is useful to use in a TimeUUIDType sorted column family. * * @param clock a ClockResolution * @return the time uuid */ public static java.util.UUID getTimeUUID(ClockResolution clock) { return getTimeUUID(clock.createClock()); }
@Test public void testDateUUIDConversion() { long originalTime = System.currentTimeMillis(); Date originalDate = new Date(originalTime); UUID originalUUID = TimeUUIDUtils.getTimeUUID(originalTime); long currentTime = TimeUUIDUtils.getTimeFromUUID(originalUUID); assertEquals(originalTime, currentTime); assertEquals(originalDate, new Date(currentTime)); }
log.info("----"); final UUID u1 = TimeUUIDUtils.getTimeUUID(originalTime);
/** * This test must be placed FIRST. Please don't change the order. * @throws Exception */ @Test @Ignore public void testTimeUUIDWithClockResolution() throws Exception { ClockResolution clock = new MicrosecondsClockResolution(); long time = clock.createClock(); // Invoke twice with same time. Both generated UUID should be the same. // Test improved algorithm. assertEquals(TimeUUIDUtils.getTimeUUID(time), java.util.UUID.fromString( new com.eaio.uuid.UUID(UUIDGen.createTime(time), UUIDGen.getClockSeqAndNode()).toString())); clock = new MicrosecondsSyncClockResolution(); // Invoke twice with a clockResolution that guarantees unique timestamp. The second must be greater // than the first one. java.util.UUID first = TimeUUIDUtils.getTimeUUID(clock); java.util.UUID second = TimeUUIDUtils.getTimeUUID(clock); assertTrue(second.compareTo(first) > 0); }
/** * Gets a new time uuid using {@link ClockResolution#createClock()} as a time generator. * It is useful to use in a TimeUUIDType sorted column family. * * @param clock a ClockResolution * @return the time uuid */ public static java.util.UUID getTimeUUID(ClockResolution clock) { return getTimeUUID(clock.createClock()); }
/** * Get all message IDs deleted before given date * * @param mailbox * @param age * @return */ public static Map<UUID, UUID> get(final String mailbox, final Date age, final int count) { UUID start = TimeUUIDUtils.getTimeUUID(age.getTime()); return get(mailbox, start, count); }
/** * Gets a new time uuid using {@link ClockResolution#createClock()} as a time generator. * It is useful to use in a TimeUUIDType sorted column family. * * @param clock a ClockResolution * @return the time uuid */ public static java.util.UUID getTimeUUID(ClockResolution clock) { return getTimeUUID(clock.createClock()); }
@Before public void setupLocal() { //setupClient(); Cluster cluster = getOrCreateCluster("MyCluster", "127.0.0.1:9170"); keyspace = createKeyspace("Keyspace1", cluster); Mutator<String> mutator = HFactory.createMutator(keyspace, StringSerializer.get()); mutator.addInsertion("zznate", "Standard1", HFactory.createStringColumn("email", "nate@datastax.com")); mutator.addInsertion("zznate", "Standard1", HFactory.createColumn("int", 1, StringSerializer.get(), IntegerSerializer.get())); mutator.addInsertion("zznate", "Standard1", HFactory.createColumn("long", 1L, StringSerializer.get(), LongSerializer.get())); timeUUID = TimeUUIDUtils.getTimeUUID(System.currentTimeMillis()); mutator.addInsertion("zznate", "Standard1", HFactory.createColumn("uuid", timeUUID, StringSerializer.get(), UUIDSerializer.get())); mutator.execute(); }
return TimeUUIDUtils.getTimeUUID(emailUs);
/** * Each invocation creates 20 rows of 50 keys each * @return */ public Integer call() { Mutator<String> mutator = HFactory.createMutator(tutorialKeyspace, StringSerializer.get()); int count = 0; String myKey = TimeUUIDUtils.getTimeUUID(tutorialKeyspace.createClock()).toString(); for (int x=0; x<1000; x++) { // assemble the insertions mutator.addInsertion(myKey,"KeyIterableCf", buildColumnFor(x)); if ( x % 50 == 0 ) { myKey = TimeUUIDUtils.getTimeUUID(tutorialKeyspace.createClock()).toString(); count++; } } mutator.execute(); log.debug("Inserted {} rows", count); return Integer.valueOf(count); } }
@Test public void testToggleMultiget() { Mutator<String> mutator = HFactory.createMutator(keyspace, StringSerializer.get()); mutator.addInsertion("patricioe", "Standard1", HFactory.createStringColumn("email", "patricioe@datastax.com")); mutator.addInsertion("patricioe", "Standard1", HFactory.createColumn("int", 2, StringSerializer.get(), IntegerSerializer.get())); mutator.addInsertion("patricioe", "Standard1", HFactory.createColumn("long", 2L, StringSerializer.get(), LongSerializer.get())); timeUUID = TimeUUIDUtils.getTimeUUID(System.currentTimeMillis()); mutator.addInsertion("patricioe", "Standard1", HFactory.createColumn("uuid", timeUUID, StringSerializer.get(), UUIDSerializer.get())); mutator.execute(); HColumnFamilyImpl<String, String> columnFamily = new HColumnFamilyImpl<String,String>(keyspace, "Standard1",StringSerializer.get(), StringSerializer.get()); columnFamily.addKey("zznate").addKey("patricioe").setCount(10); assertEquals("nate@datastax.com",columnFamily.getString("email")); assertTrue(columnFamily.hasNext()); columnFamily.next(); assertEquals("patricioe@datastax.com",columnFamily.getString("email")); assertFalse(columnFamily.hasNext()); try { columnFamily.next(); fail(); } catch (NoSuchElementException nsee) { assertNotNull(nsee); } } }