@Test public void testCallTwice() throws Exception { final MutableInt callCount = new MutableInt(0); final MutableBoolean called = new MutableBoolean(false); Polling p = new Polling() { @Override public Boolean call() throws Exception { callCount.increment(); boolean b = called.booleanValue(); called.setTrue(); return b; } }; p.poll(500, 10); assertEquals(2, callCount.intValue()); }
@Test public void testCallTimeout() throws Exception { final MutableInt callCount = new MutableInt(0); Polling p = new Polling() { @Override public Boolean call() throws Exception { callCount.increment(); return false; } }; try { p.poll(100, 10); } catch (TimeoutException e ) { assertTrue("Expected to execute call() at least 4 times, got instead only " + callCount.intValue() + " calls", callCount.intValue() > 5); return; } fail("Did not reach timeout"); }
@Test public void testCallableTwice() throws Exception { final MutableInt callCount = new MutableInt(0); final MutableBoolean called = new MutableBoolean(false); Polling p = new Polling(new Callable<Boolean>() { @Override public Boolean call() throws Exception { callCount.increment(); boolean b = called.booleanValue(); called.setTrue(); return b; } }); p.poll(500, 10); assertEquals(2, callCount.intValue()); }
@Test public void testCallableTimeout() throws Exception { final MutableInt callCount = new MutableInt(0); Polling p = new Polling(new Callable<Boolean>() { @Override public Boolean call() throws Exception { callCount.increment(); return false; } }); try { p.poll(100, 10); } catch (TimeoutException e ) { assertTrue("Expected to execute call() at least 4 times, got instead only " + callCount.intValue() + " calls", callCount.intValue() > 5); return; } fail("Did not reach timeout"); }
private void addProteinSequenceEntry(Track<Gene> track, final Gene cds, List<ProteinSequenceEntry> proteinSequences, String aminoAcid, long tripleStartIndex, int newExtendedStart, final MutableInt aminoAcidCounter) { if (tripleStartIndex >= track.getStartIndex() && tripleStartIndex <= track.getEndIndex()) { long tripleEndIndex = tripleStartIndex + 2; if (newExtendedStart != 0) { tripleEndIndex = tripleEndIndex - Math.abs(newExtendedStart); } if (tripleEndIndex > cds.getEndIndex()) { tripleEndIndex = cds.getEndIndex(); } if (!(tripleStartIndex > track.getStartIndex() && tripleEndIndex > track.getEndIndex()) && !(tripleStartIndex < track.getStartIndex() && tripleEndIndex < track.getEndIndex())) { ProteinSequenceEntry protein = new ProteinSequenceEntry(aminoAcid, track.getId(), cds.getStartIndex().longValue(), cds.getEndIndex().longValue(), tripleStartIndex, tripleEndIndex); protein.setIndex(aminoAcidCounter.longValue() - 1); proteinSequences.add(protein); } } }
private void processCds(Track<Gene> track, final Gene cds, List<ProteinSequenceEntry> proteinSequences, List<Sequence> triple, boolean isAdditionalCds, int newExtendedStart, final MutableInt aminoAcidCounter) { if (!isAdditionalCds) { boolean isNegative = StrandSerializable.NEGATIVE.equals(cds.getStrand()); // Convert nucleotide triple to amino acid. String aminoAcid = ProteinSequenceUtils.tripletToAminoAcid( triple.stream().map(Sequence::getText).collect(Collectors.joining())); long tripleStartIndex = isNegative? triple.get(2).getStartIndex().longValue() : triple.get(0).getStartIndex().longValue(); if (((newExtendedStart > 0) && isNegative) || ((newExtendedStart < 0) && !isNegative)) { tripleStartIndex = cds.getStartIndex(); } addProteinSequenceEntry(track, cds, proteinSequences, aminoAcid, tripleStartIndex, newExtendedStart, aminoAcidCounter); } }
public void invoke() { node.setNextInstruction(node.instructionPointer + 1); Method m = instruction.getMethod(); try { m.invoke(null, subsituteArguments()); node.executionState = isPortRead ? ExecutionState.READ : ExecutionState.RUN; for (Map.Entry<CommunicationPort, MutableInt> entry : writeResults.entrySet()) { CommunicationPort port = entry.getKey(); port.write(entry.getValue().intValue()); node.executionState = ExecutionState.WRITE; } } catch (Exception e) { logger.warn("Exception encountered during instruction execution: {}", e); } }
@Test public void testWorkflowInterception_WithActualParameters() throws Throwable { /* setup */ final MutableInt getEventNameCall = new MutableInt(0); doAnswer(invocation -> { Event argument = (Event) invocation.getArguments()[0]; final int currentValue = getEventNameCall.intValue(); getEventNameCall.increment(); return argument.name() + currentValue; }).when(localContext).generateEventName(any(Event.class)); final Method invokedMethod = simpleWorkflowForTest.getClass().getDeclaredMethod("simpleDummyWorkflow", StringEvent.class, IntegerEvent.class); final StringEvent testStringEvent = new StringEvent("someEvent"); final IntegerEvent testIntegerEvent = new IntegerEvent(1); /* invoke method */ workflowInterceptor.invoke(dummyInvocation(invokedMethod,new Object[]{testStringEvent,testIntegerEvent})); /* verifications */ verify(localContext,times(1)).addEvents( new EventData(SimpleWorkflowForTest.STRING_EVENT_NAME + "0", StringEvent.class.getName(), objectMapper.writeValueAsString(testStringEvent), CLIENT), new EventData(SimpleWorkflowForTest.INTEGER_EVENT_NAME + "1", IntegerEvent.class.getName(), objectMapper.writeValueAsString(testIntegerEvent), CLIENT) ); }
@Override public void process(T t) { if (pattern.checkState(t, 0)) { partialMatches.add(new MutableInt(-1)); } if (partialMatches.size() > 0) { MutableInt tempInt; Iterator<MutableInt> itr = partialMatches.iterator(); while (itr.hasNext()) { tempInt = itr.next(); tempInt.increment(); if (!pattern.checkState(t, tempInt.intValue())) { itr.remove(); } else if (tempInt.equals(patternLength)) { itr.remove(); processPatternFound(); } } } }
@Override public synchronized Object deserializeObject(byte[] objectBytes, MutableInt offset) { int length = GPOUtils.deserializeInt(objectBytes, offset); int startIndex = offset.intValue(); Map<Object, Object> primitiveMap = Maps.newHashMap(); while (startIndex + length > offset.intValue()) { int typeOrdinal = GPOUtils.deserializeInt(objectBytes, offset); GPOType gpoType = GPOType.GPO_TYPE_ARRAY[typeOrdinal]; Object key = gpoType.deserialize(objectBytes, offset); typeOrdinal = GPOUtils.deserializeInt(objectBytes, offset); gpoType = GPOType.GPO_TYPE_ARRAY[typeOrdinal]; Object value = gpoType.deserialize(objectBytes, offset); primitiveMap.put(key, value); } return primitiveMap; }
@Override public synchronized Object deserializeObject(byte[] object, MutableInt offset) { Map<String, Type> fieldToType = Maps.newHashMap(); int length = GPOUtils.deserializeInt(object, offset); int startIndex = offset.intValue(); while (startIndex + length > offset.intValue()) { Type type = Type.values()[GPOUtils.deserializeInt(object, offset)]; String value = GPOUtils.deserializeString(object, offset); fieldToType.put(value, type); } return new FieldsDescriptor(fieldToType); }
@Override public boolean accept(RegexOccurrence occurrence) { if(allowedChars == null) return true; int totalChars = 0; int totalWords = 0; int nbBadWords = 0; MutableInt badChars = new MutableInt(0); for(LabelledAnnotation a:occurrence.getLabelledAnnotations()) { WordAnnotation w = (WordAnnotation) a.getAnnotation(); totalChars += w.getCoveredText().length(); totalWords += 1; if(isBadWord(w, badChars)) nbBadWords +=1; } if(nbBadWords > 1) return false; if(totalChars <= totalWords*3 && totalWords > 1) return false; int badCharRate = 100*badChars.intValue()/totalChars; if(badCharRate >= BAD_CHAR_RATE_THRESHOLD) return false; return true; }
/** * Serializes the given {@link GPOMutable} object while excluding the provided fields from the serialization. * @param gpo The {@link GPOMutable} to serialize. * @param excludedFields The fields from the {@link GPOMutable} object to exclude. * @return A byte array containing the serialized {@link GPOMutable}. */ public static byte[] serialize(GPOMutable gpo, Fields excludedFields) { int slength = serializedLength(gpo); byte[] sbytes = new byte[slength]; MutableInt offset = new MutableInt(0); Set<String> fields = gpo.getFieldDescriptor().getFields().getFields(); Set<String> exFieldsSet = excludedFields.getFields(); for (String field : fields) { if (exFieldsSet.contains(field)) { continue; } Type type = gpo.getFieldDescriptor().getType(field); GPOType gpoType = GPOType.GPO_TYPE_ARRAY[type.ordinal()]; gpoType.serialize(gpo, field, sbytes, offset); } return sbytes; }
/** * This method deserializes a long from the given byte array from the given offset, * and increments the offset appropriately. * @param buffer The byte buffer to deserialize from. * @param offset The offset to deserialize from. * @return The deserialized long. */ public static long deserializeLong(byte[] buffer, MutableInt offset) { int offsetInt = offset.intValue(); long val = ((((long)buffer[0 + offsetInt]) & 0xFFL) << 56) | ((((long)buffer[1 + offsetInt]) & 0xFFL) << 48) | ((((long)buffer[2 + offsetInt]) & 0xFFL) << 40) | ((((long)buffer[3 + offsetInt]) & 0xFFL) << 32) | ((((long)buffer[4 + offsetInt]) & 0xFFL) << 24) | ((((long)buffer[5 + offsetInt]) & 0xFFL) << 16) | ((((long)buffer[6 + offsetInt]) & 0xFFL) << 8) | (((long)buffer[7 + offsetInt]) & 0xFFL); offset.add(Type.LONG.getByteSize()); return val; }
/** * This method deserializes a double from the given byte array from the given offset, * and increments the offset appropriately. * @param buffer The byte buffer to deserialize from. * @param offset The offset to deserialize from. * @return The deserialized double. */ public static double deserializeDouble(byte[] buffer, MutableInt offset) { int offsetInt = offset.intValue(); long val = (((long)buffer[0 + offsetInt]) & 0xFFL) << 56 | ((((long)buffer[1 + offsetInt]) & 0xFFL) << 48) | ((((long)buffer[2 + offsetInt]) & 0xFFL) << 40) | ((((long)buffer[3 + offsetInt]) & 0xFFL) << 32) | ((((long)buffer[4 + offsetInt]) & 0xFFL) << 24) | ((((long)buffer[5 + offsetInt]) & 0xFFL) << 16) | ((((long)buffer[6 + offsetInt]) & 0xFFL) << 8) | (((long)buffer[7 + offsetInt]) & 0xFFL); offset.add(Type.DOUBLE.getByteSize()); return Double.longBitsToDouble(val); }
/** * This method serializes the given double to the given byte buffer to the given offset, * the method also increments the offset appropriately. * @param valD The value to serialize. * @param buffer The byte buffer to serialize to. * @param offset The offset in the buffer to serialize to and also to increment appropriately. */ public static void serializeDouble(double valD, byte[] buffer, MutableInt offset) { long val = Double.doubleToLongBits(valD); int offsetInt = offset.intValue(); buffer[0 + offsetInt] = (byte)((val >> 56) & 0xFFL); buffer[1 + offsetInt] = (byte)((val >> 48) & 0xFFL); buffer[2 + offsetInt] = (byte)((val >> 40) & 0xFFL); buffer[3 + offsetInt] = (byte)((val >> 32) & 0xFFL); buffer[4 + offsetInt] = (byte)((val >> 24) & 0xFFL); buffer[5 + offsetInt] = (byte)((val >> 16) & 0xFFL); buffer[6 + offsetInt] = (byte)((val >> 8) & 0xFFL); buffer[7 + offsetInt] = (byte)(val & 0xFFL); offset.add(Type.DOUBLE.getByteSize()); }
@Override public synchronized Object deserializeObject(byte[] object, MutableInt offset) { int length = GPOUtils.deserializeInt(object, offset); int startIndex = offset.intValue(); if (length == 0) { return new ArrayList<GPOMutable>(); } FieldsDescriptor fd = (FieldsDescriptor)SerdeFieldsDescriptor.INSTANCE.deserializeObject(object, offset); List<GPOMutable> mutables = Lists.newArrayList(); while (startIndex + length > offset.intValue()) { GPOMutable value = GPOUtils.deserialize(fd, object, offset); mutables.add(value); } return mutables; }
@Override public synchronized Object deserializeObject(byte[] object, MutableInt offset) { int length = GPOUtils.deserializeInt(object, offset); int startIndex = offset.intValue(); List<Object> listPrimitives = Lists.newArrayList(); while (startIndex + length > offset.intValue()) { int typeOrdinal = GPOUtils.deserializeInt(object, offset); GPOType gpoType = GPOType.GPO_TYPE_ARRAY[typeOrdinal]; Object primitive = gpoType.deserialize(object, offset); listPrimitives.add(primitive); } return listPrimitives; }
/** * report how many blocks that have been released. * @param numReleasedBlocks */ @Override public void releasedBlocks(int numReleasedBlocks) { if (numReleasedBlocks == 0) { return; } if (numReleasedBlocks < 0) { throw new IllegalArgumentException("Num of released blocks should not be negative"); } /** * decrease by released blocks */ for (Object num : freeBlockNumQueue) { ((MutableInt)num).setValue(Math.max(((MutableInt)num).intValue() - numReleasedBlocks, 0)); } }
/** * This method rolls over to the next files. * @param fileName The file that you are rolling. * @throws IllegalArgumentException * @throws IOException * @throws ExecutionException */ protected void rotate(String fileName) throws IllegalArgumentException, IOException, ExecutionException { if (!this.getRotationState(fileName).rotated) { requestFinalize(fileName); counts.remove(fileName); streamsCache.invalidate(fileName); MutableInt mi = openPart.get(fileName); LOG.debug("Part file rotated {} : {}", fileName, mi.getValue()); //TODO: remove this as rotateHook is deprecated. String partFileName = getPartFileName(fileName, mi.getValue()); rotateHook(partFileName); getRotationState(fileName).rotated = true; } }
@Test public void simpleSerdeTest() { GPOByteArrayList bal = new GPOByteArrayList(); List<Object> primitiveList = Lists.newArrayList(); primitiveList.add(true); primitiveList.add(((byte)5)); primitiveList.add(((short)16000)); primitiveList.add(25000000); primitiveList.add(5000000000L); primitiveList.add('a'); primitiveList.add("tim is the coolest"); byte[] plBytes = SerdeListPrimitive.INSTANCE.serializeObject(primitiveList); bal.add(new byte[15]); bal.add(plBytes); bal.add(new byte[13]); @SuppressWarnings("unchecked") List<Object> newPrimitiveList = (List<Object>)SerdeListPrimitive.INSTANCE.deserializeObject(bal.toByteArray(), new MutableInt(15)); Assert.assertEquals(primitiveList, newPrimitiveList); }
@Test public void simpleSerdeTest() { SerdeListString sls = SerdeListString.INSTANCE; List<String> testList = Lists.newArrayList("timothy", "farkas", "is", "the", "coolest"); byte[] serializedObject = sls.serializeObject(testList); GPOByteArrayList gpoBytes = new GPOByteArrayList(); byte[] bytesA = new byte[20]; byte[] bytesB = new byte[13]; gpoBytes.add(bytesA); gpoBytes.add(serializedObject); gpoBytes.add(bytesB); MutableInt intVals = new MutableInt(bytesA.length); @SuppressWarnings("unchecked") List<String> deserializedList = (List<String>)sls.deserializeObject(gpoBytes.toByteArray(), intVals); Assert.assertEquals(testList, deserializedList); }
@Test public void simpleTest() { Map<String, Type> fieldToType = Maps.newHashMap(); fieldToType.put("a", Type.INTEGER); fieldToType.put("b", Type.CHAR); FieldsDescriptor fd = new FieldsDescriptor(fieldToType); byte[] bytes = SerdeFieldsDescriptor.INSTANCE.serializeObject(fd); FieldsDescriptor newfd = (FieldsDescriptor)SerdeFieldsDescriptor.INSTANCE.deserializeObject(bytes, new MutableInt(0)); Assert.assertEquals(fd, newfd); }
@Test public void SumTest() { SumInt si = new SumInt(); SumLong sl = new SumLong(); SumFloat sf = new SumFloat(); SumDouble sd = new SumDouble(); Assert.assertEquals(new MutableInt(10), si.accumulate(si.defaultAccumulatedValue(), 10)); Assert.assertEquals(new MutableInt(11), si.accumulate(new MutableInt(1), 10)); Assert.assertEquals(new MutableInt(22), si.merge(new MutableInt(1), new MutableInt(21))); Assert.assertEquals(new MutableLong(10L), sl.accumulate(sl.defaultAccumulatedValue(), 10L)); Assert.assertEquals(new MutableLong(22L), sl.accumulate(new MutableLong(2L), 20L)); Assert.assertEquals(new MutableLong(41L), sl.merge(new MutableLong(32L), new MutableLong(9L))); Assert.assertEquals(new MutableFloat(9.0F), sf.accumulate(sf.defaultAccumulatedValue(), 9.0F)); Assert.assertEquals(new MutableFloat(22.5F), sf.accumulate(new MutableFloat(2.5F), 20F)); Assert.assertEquals(new MutableFloat(41.0F), sf.merge(new MutableFloat(33.1F), new MutableFloat(7.9F))); Assert.assertEquals(new MutableDouble(9.0), sd.accumulate(sd.defaultAccumulatedValue(), 9.0)); Assert.assertEquals(new MutableDouble(22.5), sd.accumulate(new MutableDouble(2.5), 20.0)); Assert.assertEquals(new MutableDouble(41.0), sd.merge(new MutableDouble(33.1), new MutableDouble(7.9))); }
/** * Assign id to given annotation, add it to this container and return it. * * @param anno * @return given anno with assigned id. */ public <B extends BratAnnotation<?>> B register(B anno) { // sanity check 1 if (anno.getId() != null) { throw new IllegalArgumentException(String.format( "Can not register anno %s with non-null id", anno.getId())); } // sanity check 2 checkTypeRegistration(anno.getType()); // calc id MutableInt counter = getCounterForTypeOf(anno); String idPrefix = getPrefixForTypeOf(anno); counter.increment(); // assign id anno.setNumId(counter.longValue()); anno.setId(idPrefix + counter); // memorize add(anno); return anno; }
protected <T extends GenericEntity<Long, ?>> List<Callable<Void>> getEntityMigrationTasks(final MutableInt totalItems, final ISimpleEntityMigrationInformation<T> entityInformation, final IGenericEntityService<Long, T> entityService) { if (entityInformation.getParameterIds() == null) { throw new IllegalStateException("ParameterIds null. Pour importer les entités par lot, il faut spécifier ParameterIds."); } final List<Long> entityIds = ImmutableList.copyOf(getJdbcTemplate().queryForList(entityInformation.getSqlAllIds(), Long.class)); List<List<Long>> entityIdsPartitions = Lists.partition(entityIds, 100); List<Callable<Void>> callables = Lists.newArrayList(); for (final List<Long> entityIdsPartition : entityIdsPartitions) { callables.add(getEntityMigrationTask(totalItems, entityIdsPartition, entityInformation, entityService)); } clazzSet.add(entityInformation.getEntityClass()); return callables; }
@Override public void fsync() { super.fsync(); val count = new MutableInt(); Stream.of( data.values() .stream() .filter( m -> m.modified >= lastFsync ) ) .grouped( bulkSize ) .forEach( list -> { count.add( list.size() ); final List<? extends WriteModel<Metadata<T>>> bulk = Lists.map( list, metadata -> { val id = identifier.get( metadata.object ); return new ReplaceOneModel<>( eq( "_id", new ObjectId( id ) ), metadata, UPDATE_OPTIONS_UPSERT ); } ); collection.bulkWrite( bulk ); } ); log.info( "[{}] fsync total: {}, modified: {}", collection.getNamespace(), size(), count.intValue() ); lastFsync = System.currentTimeMillis(); }
@Test public void testDeepClone() { final CloneableVO vo = new CloneableVO(); vo.setValue(5); vo.setMutableValue(new MutableInt(5)); vo.setCloneableClass(new CloneableClass()); vo.getCloneableClass().setOtherValue(8); vo.setCloneableVO(new CloneableVO()); vo.getCloneableVO().setValue(6); final CloneableVO voClone = (CloneableVO) vo.clone(); Assertions.assertThat(vo).isNotSameAs(voClone); //FST does not clone immutable values Assertions.assertThat(vo.getValue()).isSameAs(voClone.getValue()); Assertions.assertThat(vo.getValue()).isEqualTo(voClone.getValue()); //only mutable ones Assertions.assertThat(vo.getMutableValue()).isNotSameAs(voClone.getMutableValue()); Assertions.assertThat(vo.getMutableValue()).isEqualTo(voClone.getMutableValue()); //and cloneables Assertions.assertThat(vo.getCloneableClass()).isNotSameAs(voClone.getCloneableClass()); Assertions.assertThat(vo.getCloneableClass()).isEqualTo(voClone.getCloneableClass()); //and value objects Assertions.assertThat(vo.getCloneableVO()).isNotSameAs(voClone.getCloneableVO()); Assertions.assertThat(vo.getCloneableVO()).isEqualTo(voClone.getCloneableVO()); }
@Test public void testShallowClone() { final CloneableVO vo = new CloneableVO(); vo.setValue(5); vo.setMutableValue(new MutableInt(5)); vo.setCloneableClass(new CloneableClass()); vo.setCloneableVO(new CloneableVO()); vo.getCloneableVO().setValue(6); final CloneableVO voClone = (CloneableVO) vo.shallowClone(); Assertions.assertThat(vo).isNotSameAs(voClone); //shallow clone does not clone constants Assertions.assertThat(vo.getValue()).isSameAs(voClone.getValue()); Assertions.assertThat(vo.getValue()).isEqualTo(voClone.getValue()); //also not mutable values Assertions.assertThat(vo.getMutableValue()).isSameAs(voClone.getMutableValue()); Assertions.assertThat(vo.getMutableValue()).isEqualTo(voClone.getMutableValue()); //nor cloneables Assertions.assertThat(vo.getCloneableClass()).isSameAs(voClone.getCloneableClass()); Assertions.assertThat(vo.getCloneableClass()).isEqualTo(voClone.getCloneableClass()); //and not value objects Assertions.assertThat(vo.getCloneableVO()).isSameAs(voClone.getCloneableVO()); Assertions.assertThat(vo.getCloneableVO()).isEqualTo(voClone.getCloneableVO()); }
@Test public void testShallowCloneReflective() { final CloneableVO vo = new CloneableVO(); vo.setValue(5); vo.setMutableValue(new MutableInt(5)); vo.setCloneableClass(new CloneableClass()); vo.getCloneableClass().setOtherValue(8); vo.setCloneableVO(new CloneableVO()); vo.getCloneableVO().setValue(6); final CloneableVO voClone = (CloneableVO) vo.shallowCloneReflective(); Assertions.assertThat(vo).isNotSameAs(voClone); //refletive clone does not clone constants Assertions.assertThat(vo.getValue()).isSameAs(voClone.getValue()); Assertions.assertThat(vo.getValue()).isEqualTo(voClone.getValue()); //also it does not clone classes that do not implement cloneable Assertions.assertThat(vo.getMutableValue()).isSameAs(voClone.getMutableValue()); Assertions.assertThat(vo.getMutableValue()).isEqualTo(voClone.getMutableValue()); //but it does cloneables Assertions.assertThat(vo.getCloneableClass()).isNotSameAs(voClone.getCloneableClass()); Assertions.assertThat(vo.getCloneableClass()).isEqualTo(voClone.getCloneableClass()); //and value objects Assertions.assertThat(vo.getCloneableVO()).isNotSameAs(voClone.getCloneableVO()); Assertions.assertThat(vo.getCloneableVO()).isEqualTo(voClone.getCloneableVO()); }
@Test public void testShallowCloneReflectiveOnFields() { final FieldCloneableVO vo = new FieldCloneableVO(); vo.value = 5; vo.mutableValue = new MutableInt(5); vo.cloneableClass = new FieldCloneableClass(); vo.cloneableClass.otherValue = 8; vo.cloneableVO = new FieldCloneableVO(); vo.cloneableVO.value = 6; final FieldCloneableVO voClone = (FieldCloneableVO) vo.shallowCloneReflective(); Assertions.assertThat(vo).isNotSameAs(voClone); //refletive clone does not clone constants Assertions.assertThat(vo.value).isSameAs(voClone.value); Assertions.assertThat(vo.value).isEqualTo(voClone.value); //also it does not clone classes that do not implement cloneable Assertions.assertThat(vo.mutableValue).isSameAs(voClone.mutableValue); Assertions.assertThat(vo.mutableValue).isEqualTo(voClone.mutableValue); //but it does cloneables Assertions.assertThat(vo.cloneableClass).isNotSameAs(voClone.cloneableClass); Assertions.assertThat(vo.cloneableClass).isEqualTo(voClone.cloneableClass); //and value objects Assertions.assertThat(vo.cloneableVO).isNotSameAs(voClone.cloneableVO); Assertions.assertThat(vo.cloneableVO).isEqualTo(voClone.cloneableVO); }
@Test public void testCallOnce() throws Exception { final MutableInt callCount = new MutableInt(0); Polling p = new Polling() { @Override public Boolean call() throws Exception { callCount.increment(); return true; } }; p.poll(500, 10); assertEquals(1, callCount.intValue()); }
@Test public void testNegativeTimeout() throws Exception { final MutableInt callCount = new MutableInt(0); Polling p = new Polling() { @Override public Boolean call() throws Exception { callCount.increment(); return true; } }; p.poll(-1, 10); assertEquals(1, callCount.intValue()); }
@Test public void testCallableOnce() throws Exception { final MutableInt callCount = new MutableInt(0); final MutableBoolean called = new MutableBoolean(false); Polling p = new Polling(new Callable<Boolean>() { @Override public Boolean call() throws Exception { callCount.increment(); return true; } }); p.poll(500, 10); assertEquals(1, callCount.intValue()); }
private static Map<ExpressionSegment, Expression> createExpressionSegmentMap(List<Segment> segments) { MutableInt id = new MutableInt(); return segments.stream() .filter(s -> s instanceof ExpressionSegment) .map(s -> (ExpressionSegment) s) .collect(Collectors.toMap( e -> e, e -> new ExpressionImpl(id.getAndIncrement(), e.getValue()) )); }
@Test public void test_chunks_sequenced() throws IOException { MutableInt parsed = new MutableInt(0); AsyncJsonParser parser = new AsyncJsonParser(root -> { parsed.increment(); try { Model deserialized = mapper.treeToValue(root, Model.class); Assert.assertEquals(deserialized, model); } catch (JsonProcessingException e) { Assert.fail(e.getMessage()); } }); byte[] bytes = new ObjectMapper().writeValueAsBytes(model); byte[] allBytes = new byte[3 * bytes.length]; System.arraycopy(bytes, 0, allBytes, bytes.length * 0, bytes.length); System.arraycopy(bytes, 0, allBytes, bytes.length * 1, bytes.length); System.arraycopy(bytes, 0, allBytes, bytes.length * 2, bytes.length); final int CHUNK_SIZE = 20; for (int i = 0; i < allBytes.length; i += CHUNK_SIZE) { byte[] chunk = new byte[20]; int start = Math.min(allBytes.length, i); int len = Math.min(CHUNK_SIZE, allBytes.length - i); System.arraycopy(allBytes, start, chunk, 0, len); System.out.println(new String(chunk)); parser.consume(chunk, len); } Assert.assertEquals(3, parsed.intValue()); }
public SameSchemaDeployExecutionDao(SqlExecutor sqlExecutor, DbMetadataManager dbMetadataManager, DbPlatform platform, ImmutableSet<PhysicalSchema> physicalSchemas, String tableSqlSuffix, DbEnvironment env, ChangeTypeBehaviorRegistry changeTypeBehaviorRegistry) { this.sqlExecutor = sqlExecutor; this.jdbc = sqlExecutor.getJdbcTemplate(); this.dbMetadataManager = dbMetadataManager; this.platform = platform; this.physicalSchemas = physicalSchemas; this.nextIdBySchema = physicalSchemas .toMap(Functions.<PhysicalSchema>getPassThru(), new Function<PhysicalSchema, MutableInt>() { @Override public MutableInt valueOf(PhysicalSchema object) { return new MutableInt(1); } }) .toImmutable(); this.tableSqlSuffix = tableSqlSuffix; this.env = env; this.changeTypeBehaviorRegistry = changeTypeBehaviorRegistry; Function<String, String> convertDbObjectName = platform.convertDbObjectName(); this.deployExecutionTableName = convertDbObjectName.valueOf(DEPLOY_EXECUTION_TABLE_NAME); this.deployExecutionAttributeTableName = convertDbObjectName.valueOf(DEPLOY_EXECUTION_ATTRIBUTE_TABLE_NAME); this.idColName = convertDbObjectName.valueOf("ID"); this.statusColName = convertDbObjectName.valueOf("STATUS"); this.deployTimeColName = convertDbObjectName.valueOf("DEPLOYTIME"); this.executorIdColName = convertDbObjectName.valueOf("EXECUTORID"); this.toolVersionColName = convertDbObjectName.valueOf("TOOLVERSION"); this.initCommandColName = convertDbObjectName.valueOf("INIT_COMMAND"); this.rollbackCommandColName = convertDbObjectName.valueOf("ROLLBACK_COMMAND"); this.requesterIdColName = convertDbObjectName.valueOf("REQUESTERID"); this.reasonColName = convertDbObjectName.valueOf("REASON"); this.productVersionColName = convertDbObjectName.valueOf("PRODUCTVERSION"); this.dbSchemaColName = convertDbObjectName.valueOf("DBSCHEMA"); this.allMainColumns = Lists.immutable.with(idColName, statusColName, deployTimeColName, executorIdColName, toolVersionColName, initCommandColName, rollbackCommandColName, requesterIdColName, reasonColName, dbSchemaColName, productVersionColName); this.deployExecutionIdColName = convertDbObjectName.valueOf("DEPLOYEXECUTIONID"); this.attrNameColName = convertDbObjectName.valueOf("ATTRNAME"); this.attrValueColName = convertDbObjectName.valueOf("ATTRVALUE"); this.allAttrColumns = Lists.immutable.with(deployExecutionIdColName, attrNameColName, attrValueColName); }
public void add(Collection<Integer> data) { for(Integer value : data) { if(!histogram.containsKey(value)) { histogram.put(value, new MutableInt(1)); } else { histogram.get(value).increment(); } } }