Package com.alibaba.otter.shared.etl.model

Examples of com.alibaba.otter.shared.etl.model.DbBatch


        InputStream input = null;
        JSONReader reader = null;
        try {
            input = new BufferedInputStream(new FileInputStream(archiveFile));
            DbBatch dbBatch = new DbBatch();
            byte[] lengthBytes = new byte[4];
            input.read(lengthBytes);
            int length = ByteUtils.bytes2int(lengthBytes);
            BatchProto.RowBatch rowbatchProto = BatchProto.RowBatch.parseFrom(new LimitedInputStream(input, length));
            // 构造原始的model对象
            RowBatch rowBatch = new RowBatch();
            rowBatch.setIdentity(build(rowbatchProto.getIdentity()));
            for (BatchProto.RowData rowDataProto : rowbatchProto.getRowsList()) {
                EventData eventData = new EventData();
                eventData.setPairId(rowDataProto.getPairId());
                eventData.setTableId(rowDataProto.getTableId());
                eventData.setTableName(rowDataProto.getTableName());
                eventData.setSchemaName(rowDataProto.getSchemaName());
                eventData.setEventType(EventType.valuesOf(rowDataProto.getEventType()));
                eventData.setExecuteTime(rowDataProto.getExecuteTime());
                // add by ljh at 2012-10-31
                if (StringUtils.isNotEmpty(rowDataProto.getSyncMode())) {
                    eventData.setSyncMode(SyncMode.valuesOf(rowDataProto.getSyncMode()));
                }
                if (StringUtils.isNotEmpty(rowDataProto.getSyncConsistency())) {
                    eventData.setSyncConsistency(SyncConsistency.valuesOf(rowDataProto.getSyncConsistency()));
                }
                // 处理主键
                List<EventColumn> keys = new ArrayList<EventColumn>();
                for (BatchProto.Column columnProto : rowDataProto.getKeysList()) {
                    keys.add(buildColumn(columnProto));
                }
                eventData.setKeys(keys);
                // 处理old主键
                if (CollectionUtils.isEmpty(rowDataProto.getOldKeysList()) == false) {
                    List<EventColumn> oldKeys = new ArrayList<EventColumn>();
                    for (BatchProto.Column columnProto : rowDataProto.getOldKeysList()) {
                        oldKeys.add(buildColumn(columnProto));
                    }
                    eventData.setOldKeys(oldKeys);
                }
                // 处理具体的column value
                List<EventColumn> columns = new ArrayList<EventColumn>();
                for (BatchProto.Column columnProto : rowDataProto.getColumnsList()) {
                    columns.add(buildColumn(columnProto));
                }
                eventData.setColumns(columns);

                eventData.setRemedy(rowDataProto.getRemedy());
                eventData.setSize(rowDataProto.getSize());
                // 添加到总记录
                rowBatch.merge(eventData);
            }
            dbBatch.setRowBatch(rowBatch);

            input.read(lengthBytes);
            length = ByteUtils.bytes2int(lengthBytes);
            BatchProto.FileBatch filebatchProto = BatchProto.FileBatch.parseFrom(new LimitedInputStream(input, length));
            // 构造原始的model对象
            FileBatch fileBatch = new FileBatch();
            fileBatch.setIdentity(build(filebatchProto.getIdentity()));
            for (BatchProto.FileData fileDataProto : filebatchProto.getFilesList()) {
                FileData fileData = new FileData();
                fileData.setPairId(fileDataProto.getPairId());
                fileData.setTableId(fileDataProto.getTableId());
                fileData.setEventType(EventType.valuesOf(fileDataProto.getEventType()));
                fileData.setLastModifiedTime(fileDataProto.getLastModifiedTime());
                fileData.setNameSpace(fileDataProto.getNamespace());
                fileData.setPath(fileDataProto.getPath());
                fileData.setSize(fileDataProto.getSize());
                // 添加到filebatch中
                fileBatch.getFiles().add(fileData);
            }
            dbBatch.setFileBatch(fileBatch);
            return dbBatch;
        } catch (IOException e) {
            throw new PipeException("deserial_error", e);
        } finally {
            IOUtils.closeQuietly(reader);
View Full Code Here


                            for (EventData data : eventData) {
                                rowBatch.merge(data);
                            }

                            long nextNodeId = etlEventData.getNextNid();
                            List<PipeKey> pipeKeys = rowDataPipeDelegate.put(new DbBatch(rowBatch), nextNodeId);
                            etlEventData.setDesc(pipeKeys);
                            etlEventData.setNumber((long) eventData.size());
                            etlEventData.setFirstTime(startTime); // 使用原始数据的第一条
                            etlEventData.setBatchId(message.getId());
View Full Code Here

        column.setNull(false);
        eventData.getColumns().add(column);

        rowBatch.merge(eventData);

        DbBatch dbBatch = new DbBatch();
        dbBatch.setRowBatch(rowBatch);
        dbBatch.setFileBatch(fileBatch);

        HttpPipeKey key = rowDataHttpPipe.put(dbBatch);
        DbBatch target = rowDataHttpPipe.get(key);

        want.bool(target.getRowBatch().getIdentity().equals(identity));
        want.object(target).notNull();
    }
View Full Code Here

            pipe.afterPropertiesSet();
        } catch (Exception e) {
            want.fail();
        }

        DbBatch source = new DbBatch();
        RowBatch rowBatch = new RowBatch();
        Identity identity = new Identity();
        identity.setChannelId(100L);
        identity.setPipelineId(100L);
        identity.setProcessId(100L);
        rowBatch.setIdentity(identity);
        source.setRowBatch(rowBatch);

        MemoryPipeKey key = pipe.put(source);
        DbBatch target = pipe.get(key);
        want.bool(source == target).is(true);// 引用为同一个
    }
View Full Code Here

            pipe.afterPropertiesSet();
        } catch (Exception e) {
            want.fail();
        }

        DbBatch source = new DbBatch();
        RowBatch rowBatch = new RowBatch();
        Identity identity = new Identity();
        identity.setChannelId(100L);
        identity.setPipelineId(100L);
        identity.setProcessId(100L);
        rowBatch.setIdentity(identity);
        source.setRowBatch(rowBatch);

        MemoryPipeKey key = pipe.put(source);
        try {
            Thread.sleep(1500L);
        } catch (InterruptedException e) {
            want.fail();
        }
        DbBatch target = pipe.get(key);
        want.bool(target == null).is(true);// 返回结果为空
    }
View Full Code Here

public class RpcPipeTest extends BaseOtterTest {

    @Test
    public void test_ok() {
        final DbBatch source = new DbBatch();
        RowBatch rowBatch = new RowBatch();
        Identity identity = new Identity();
        identity.setChannelId(100L);
        identity.setPipelineId(100L);
        identity.setProcessId(100L);
        rowBatch.setIdentity(identity);
        source.setRowBatch(rowBatch);

        final RowDataRpcPipe pipe = new RowDataRpcPipe();
        try {
            pipe.afterPropertiesSet();
        } catch (Exception e) {
            want.fail();
        }
        Mockit.setUpMock(NodeCommmunicationClient.class, new Object() {

            @Mock
            public Object call(Long nid, final Event event) {
                try {
                    return TestUtils.invokeMethod(pipe, "onGet", event);
                } catch (Exception e) {
                    want.fail();
                }

                return null;
            }

        });

        Mockit.setUpMock(RowDataRpcPipe.class, new Object() {

            @Mock
            private Long getNid() {
                return 1L;
            }

        });
        pipe.setNodeCommmunicationClient(new NodeCommmunicationClient());
        RpcPipeKey key = pipe.put(source);
        DbBatch target = pipe.get(key);
        want.bool(source.getRowBatch().getIdentity().equals(target.getRowBatch().getIdentity())).is(true);// identify相等
    }
View Full Code Here

    }

    @Test
    public void test_timeout() {

        final DbBatch source = new DbBatch();
        RowBatch rowBatch = new RowBatch();
        Identity identity = new Identity();
        identity.setChannelId(100L);
        identity.setPipelineId(100L);
        identity.setProcessId(100L);
        rowBatch.setIdentity(identity);
        source.setRowBatch(rowBatch);

        final RowDataRpcPipe pipe = new RowDataRpcPipe();
        pipe.setTimeout(1 * 1000L);// 1s后超时
        try {
            pipe.afterPropertiesSet();
        } catch (Exception e) {
            want.fail();
        }
        Mockit.setUpMock(NodeCommmunicationClient.class, new Object() {

            @Mock
            public Object call(Long nid, final Event event) {
                try {
                    return TestUtils.invokeMethod(pipe, "onGet", event);
                } catch (Exception e) {
                    want.fail();
                }

                return null;
            }

        });

        Mockit.setUpMock(RowDataRpcPipe.class, new Object() {

            @Mock
            private Long getNid() {
                return 1L;
            }

        });
        pipe.setNodeCommmunicationClient(new NodeCommmunicationClient());

        RpcPipeKey key = pipe.put(source);
        try {
            Thread.sleep(1500L);
        } catch (InterruptedException e) {
            want.fail();
        }
        DbBatch target = pipe.get(key);
        want.bool(target == null).is(true);// 返回结果为空
    }
View Full Code Here

                eventData.setTableName("columns");
                rowBatch.merge(eventData);
            }
        }

        databaseExtractor.extract(new DbBatch(rowBatch));
        want.number(rowBatch.getDatas().size()).isEqualTo(count);
    }
View Full Code Here

                eventData.setSyncConsistency(SyncConsistency.MEDIA);
                rowBatch.merge(eventData);
            }
        }

        databaseExtractor.extract(new DbBatch(rowBatch));

        want.number(rowBatch.getDatas().size()).isEqualTo(count);
    }
View Full Code Here

                eventData.setTableName("retl_buffer");
                rowBatch.merge(eventData);
            }
        }

        DbBatch dbBatch = new DbBatch(rowBatch);
        freedomExtractor.extract(dbBatch);
        want.collection(dbBatch.getRowBatch().getDatas()).sizeEq(count * count);
    }
View Full Code Here

TOP

Related Classes of com.alibaba.otter.shared.etl.model.DbBatch

Copyright © 2018 www.massapicom. 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.