Examples of BSONTimestamp


Examples of org.bson.types.BSONTimestamp

    @Test
    public void testTimestamp()
        throws MongoException {

        DBCollection c = collection;
        c.save( BasicDBObjectBuilder.start().add( "y" , new BSONTimestamp() ).get() );

        BSONTimestamp t = (BSONTimestamp)c.findOne().get("y");
        assert( t.getTime() > 0 );
        assert( t.getInc() > 0 );
    }

Examples of org.bson.types.BSONTimestamp

        _put(name, value);
    }

    @Override
    public void gotTimestamp( String name , int time , int inc ){
        _put( name , new BSONTimestamp( time , inc ) );
    }

Examples of org.bson.types.BSONTimestamp

        ObjectId oid = new ObjectId();
        ObjectId test_oid = new ObjectId();
        ObjectId test_ref_id = new ObjectId();
        DBObject test_doc = new BasicDBObject( "abc", "12345" );
        String[] test_arr = new String[] { "foo" , "bar" , "baz" , "x" , "y" , "z" };
        BSONTimestamp test_tsp = new BSONTimestamp();
        Date test_date = new Date();
        Binary test_bin = new Binary( "scott".getBytes() );
        UUID test_uuid = UUID.randomUUID();
        Pattern test_regex = Pattern.compile( "^test.*regex.*xyz$", Pattern.CASE_INSENSITIVE );
        BasicDBObjectBuilder b = BasicDBObjectBuilder.start();

Examples of org.bson.types.BSONTimestamp

            case BSON.NUMBER_INT:
                return _input.getInt( record.valueOffset );
            case BSON.TIMESTAMP:
                int inc = _input.getInt( record.valueOffset );
                int time = _input.getInt( record.valueOffset + 4 );
                return new BSONTimestamp( time, inc );
            case BSON.DATE:
                return new Date( _input.getLong( record.valueOffset ) );
            case BSON.NUMBER_LONG:
                return _input.getLong( record.valueOffset );
            case BSON.NUMBER:

Examples of org.bson.types.BSONTimestamp

    @Test
    public void testWriteTimestamp() {
        writer.writeStartDocument();

        writer.writeTimestamp("t1", new BSONTimestamp(123999401, 44332));

        writer.writeEndDocument();

        final byte[] expectedValues = {17, 0, 0, 0, 17, 116, 49, 0, 44, -83, 0, 0, -87, 20, 100, 7, 0};
        assertArrayEquals(expectedValues, buffer.toByteArray());

Examples of org.bson.types.BSONTimestamp

        assert (oid.equals(new ObjectId("4d83ab3ea39562db9c1ae2ae")));
        DBRef ref = (DBRef) a.get("ref");
        assert (ref.equals(new DBRef(null, "test.test", new ObjectId("4d83ab59a39562db9c1ae2af"))));
        assert (a.get("code").equals(new Code("asdfdsa")));
        assert (a.get("codews").equals(new CodeWScope("ggggg", new BasicBSONObject())));
        assert (a.get("ts").equals(new BSONTimestamp(1300474885, 10)));
        assert (a.get("uuid").equals(UUID.fromString("60f65152-6d4a-4f11-9c9b-590b575da7b5")));
        String json2 = JSON.serialize(a);
        BasicDBObject b = (BasicDBObject) JSON.parse(json2);
        a.equals(b);
        assert (a.equals(b));

Examples of org.bson.types.BSONTimestamp

        buf = new StringBuilder();
        serializer.serialize(testObj, buf);
        assertEquals(buf.toString(), "{ \"boolean\" : true}");
       
        // test  BSON_TIMESTAMP,
        testObj = new BasicDBObject("timestamp", new BSONTimestamp());
        buf = new StringBuilder();
        serializer.serialize(testObj, buf);
        assertEquals(buf.toString(), "{ \"timestamp\" : { \"$ts\" : 0 , \"$inc\" : 0}}");
       
        // test  BYTE_ARRAY

Examples of org.bson.types.BSONTimestamp

        serializer.serialize(new Binary(b), buf);
        assertEquals(buf.toString(), "{ \"$binary\" : \""+base64+"\" , \"$type\" : 0}");
       
        // test  BSON_TIMESTAMP
        buf = new StringBuilder();
        serializer.serialize(new BSONTimestamp(123, 456), buf);
        assertEquals(buf.toString(), "{ \"$timestamp\" : { \"t\" : 123 , \"i\" : 456}}");
       
        // test  BYTE_ARRAY
        buf = new StringBuilder();
        serializer.serialize(b, buf);

Examples of org.bson.types.BSONTimestamp

        assertArrayEquals(parsedBinary.getData(), new byte[]{97, 98, 99, 100});
    }

    @Test
    public void timestampParsing() {
        BSONTimestamp timestamp = (BSONTimestamp) JSON.parse(("{ \"$timestamp\" : { \"t\": 123, \"i\": 456 } }"));
        assertEquals(timestamp.getInc(), 456);
        assertEquals(timestamp.getTime(), 123);
    }

Examples of org.bson.types.BSONTimestamp

            super(serializer);
        }

        @Override
        public void serialize(Object obj, StringBuilder buf) {
            BSONTimestamp t = (BSONTimestamp) obj;
            BasicDBObject temp = new BasicDBObject();
            temp.put("$ts", Integer.valueOf(t.getTime()));
            temp.put("$inc", Integer.valueOf(t.getInc()));
            serializer.serialize(temp, buf);
        }
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.