@Test @SuppressWarnings("unchecked") public void modificationDuringTransactionCausesAbort() throws Exception { Map<String, String> testMap = getRuntime().getObjectsView().open(CorfuRuntime.getStreamID("A"), SMRMap.class); assertThat(testMap.put("a", "z")); getRuntime().getObjectsView().TXBegin(); assertThat(testMap.put("a", "a")).isEqualTo("z"); assertThat(testMap.put("a", "b")).isEqualTo("a"); assertThat(testMap.get("a")).isEqualTo("b"); CompletableFuture cf = CompletableFuture.runAsync( () -> { Map<String, String> testMap2 = getRuntime() .getObjectsView() .open( UUID.nameUUIDFromBytes("A".getBytes()), SMRMap.class, null, EnumSet.of(ObjectOpenOptions.NO_CACHE), SerializerType.JSON); testMap2.put("a", "f"); }); cf.join(); assertThatThrownBy(() -> getRuntime().getObjectsView().TXEnd()) .isInstanceOf(TransactionAbortedException.class); }
static { try { emptyVersion = UUID.nameUUIDFromBytes(MessageDigest.getInstance("MD5").digest()); } catch (NoSuchAlgorithmException e) { throw new AssertionError(); } }
/** * The generated UUID of a page is based on the Wiki name and the page name (or path). * * @param p * @return * @throws IOException */ private String mkUuid(String wiki, String name) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); out.write(wiki.getBytes("UTF-8")); out.write(name.getBytes("UTF-8")); return UUID.nameUUIDFromBytes(out.toByteArray()).toString(); }
// [JACKSON-726] public void testUUIDKeyMap() throws Exception { ObjectMapper mapper = new ObjectMapper(); UUID key = UUID.nameUUIDFromBytes("foobar".getBytes("UTF-8")); String JSON = "{ \"" + key + "\":4}"; Map<UUID, Object> result = mapper.readValue(JSON, new TypeReference<Map<UUID, Object>>() {}); assertNotNull(result); assertEquals(1, result.size()); Object ob = result.keySet().iterator().next(); assertNotNull(ob); assertEquals(UUID.class, ob.getClass()); assertEquals(key, ob); }
private void writeSolr(SpectralClustering cluster) { Map<Integer, List<Doc>> map = new HashMap<Integer, List<Doc>>(); int[] lab = cluster.getClusterLabel(); for (int x = 0; x < lab.length; x++) { final Doc doc = list.get(x); if (!map.containsKey(new Integer(lab[x]))) { map.put( new Integer(lab[x]), new ArrayList<Doc>() { { add(doc); } }); } else { map.get(new Integer(lab[x])).add(doc); } } for (Map.Entry<Integer, List<Doc>> e : map.entrySet()) { System.out.println("type:" + e.getKey()); if (e.getValue().size() < 10) { StringBuffer query = new StringBuffer(); for (Doc doc : e.getValue()) { query.append("url:\"").append(doc.url).append("\""); query.append(" OR "); } query.delete(query.lastIndexOf("OR"), query.length()); String groupId = UUID.nameUUIDFromBytes(query.toString().getBytes()).toString(); List<Map<String, Object>> toSave = new ArrayList<Map<String, Object>>(); System.out.println("group:" + groupId + " = " + e.getValue().size()); List<SolrDocument> list = (List<SolrDocument>) indexDao.sortList(query.toString(), 1, 100, "infoTime_dt desc"); Date newest = new Date(0); int useful = 1; for (SolrDocument doc : list) { Date date = (Date) doc.get("infoTime_dt"); if (date.getTime() > newest.getTime()) {} Map<String, Object> inputDoc = new HashMap<String, Object>(doc); inputDoc.put("useful_i", useful); inputDoc.put("sim_i", list.size()); inputDoc.put("group_s", groupId); toSave.add(inputDoc); useful = 0; } indexDao.addIndex(toSave); } } }
/** * Read schema from system table and calculate MD5 digest of every row, resulting digest will be * converted into UUID which would act as content-based version of the schema. */ public void updateVersion() { try { MessageDigest versionDigest = MessageDigest.getInstance("MD5"); for (Row row : SystemTable.serializedSchema()) { if (invalidSchemaRow(row) || ignoredSchemaRow(row)) continue; row.cf.updateDigest(versionDigest); } version = UUID.nameUUIDFromBytes(versionDigest.digest()); SystemTable.updateSchemaVersion(version); } catch (Exception e) { throw new RuntimeException(e); } }
public static void populateStandardCustomDSProps( Map<String, String> dsProps, DataService dataService, Config config) { String dsInfo = dataService.getTenantId() + "#" + dataService.getName() + "#" + config.getConfigId(); dsProps.put( DBConstants.CustomDataSource.DATASOURCE_ID, UUID.nameUUIDFromBytes(dsInfo.getBytes(Charset.forName(DBConstants.DEFAULT_CHAR_SET_TYPE))) .toString()); if (log.isDebugEnabled()) { log.debug( "Custom Inline Data Source; ID: " + dsInfo + " UUID:" + dsProps.get(DBConstants.CustomDataSource.DATASOURCE_ID)); } }
public final UUID getTranslatedUuid(@NonNull String player, boolean expensiveLookups) { // If the player is online, give them their UUID. // Remember, local data > remote data. if (ProxyServer.getInstance().getPlayer(player) != null) return ProxyServer.getInstance().getPlayer(player).getUniqueId(); // Check if it exists in the map CachedUUIDEntry cachedUUIDEntry = nameToUuidMap.get(player.toLowerCase()); if (cachedUUIDEntry != null) { if (!cachedUUIDEntry.expired()) return cachedUUIDEntry.getUuid(); else nameToUuidMap.remove(player); } // Check if we can exit early if (UUID_PATTERN.matcher(player).find()) { return UUID.fromString(player); } if (MOJANGIAN_UUID_PATTERN.matcher(player).find()) { // Reconstruct the UUID return UUIDFetcher.getUUID(player); } // If we are in offline mode, UUID generation is simple. // We don't even have to cache the UUID, since this is easy to recalculate. if (!plugin.getProxy().getConfig().isOnlineMode()) { return UUID.nameUUIDFromBytes(("OfflinePlayer:" + player).getBytes(Charsets.UTF_8)); } // Let's try Redis. try (Jedis jedis = plugin.getPool().getResource()) { String stored = jedis.hget("uuid-cache", player.toLowerCase()); if (stored != null) { // Found an entry value. Deserialize it. CachedUUIDEntry entry = RedisBungee.getGson().fromJson(stored, CachedUUIDEntry.class); // Check for expiry: if (entry.expired()) { jedis.hdel("uuid-cache", player.toLowerCase()); // Doesn't hurt to also remove the UUID entry as well. jedis.hdel("uuid-cache", entry.getUuid().toString()); } else { nameToUuidMap.put(player.toLowerCase(), entry); uuidToNameMap.put(entry.getUuid(), entry); return entry.getUuid(); } } // That didn't work. Let's ask Mojang. if (!expensiveLookups || !ProxyServer.getInstance().getConfig().isOnlineMode()) return null; Map<String, UUID> uuidMap1; try { uuidMap1 = new UUIDFetcher(Collections.singletonList(player)).call(); } catch (Exception e) { plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID from Mojang for " + player, e); return null; } for (Map.Entry<String, UUID> entry : uuidMap1.entrySet()) { if (entry.getKey().equalsIgnoreCase(player)) { persistInfo(entry.getKey(), entry.getValue(), jedis); return entry.getValue(); } } } catch (JedisException e) { plugin.getLogger().log(Level.SEVERE, "Unable to fetch UUID for " + player, e); } return null; // Nope, game over! }