import { IChannelServices } from "@fluidframework/datastore-definitions" ; import { MockFluidDataStoreRuntime , MockContainerRuntimeFactory , MockEmptyDeltaConnection , MockStorage , } from "@fluidframework/test-runtime-utils" ; import { SharedMatrix , SharedMatrixFactory } from ".." ; import { expectSize , setCorners , checkCorners } from "./utils" ; const enum Const { excelMaxRows = 1048576 , excelMaxCols = 16384 } async function summarize < T > ( matrix ) { const objectStorage = MockStorage . createFromSummary ( matrix . getAttachSummary ( ) . summary ) ; const dataStoreRuntime = new MockFluidDataStoreRuntime ( ) ; dataStoreRuntime . local = true ; const matrix2 = new SharedMatrix < T > ( dataStoreRuntime , `load(${ matrix . id })` , SharedMatrixFactory . Attributes ) ; await matrix2 . load ( { deltaConnection : new MockEmptyDeltaConnection ( ) , objectStorage } ) ; expectSize ( matrix2 , matrix . rowCount , matrix . colCount ) ; return matrix2 ; } describe ( "Big Matrix" , function ( ) { this . timeout ( 10000 ) ; describe ( `Excel-size matrix (${ Const . excelMaxRows }x${ Const . excelMaxCols })` , ( ) => { let matrix1 ; let matrix2 ; let dataStoreRuntime1 ; let containerRuntimeFactory ; beforeEach ( async ( ) => { containerRuntimeFactory = new MockContainerRuntimeFactory ( ) ; dataStoreRuntime1 = new MockFluidDataStoreRuntime ( ) ; const containerRuntime1 = containerRuntimeFactory . createContainerRuntime ( dataStoreRuntime1 ) ; const services1 = { deltaConnection : containerRuntime1 . createDeltaConnection ( ) , objectStorage : new MockStorage ( ) } ; matrix1 = new SharedMatrix ( dataStoreRuntime1 , "matrix1" , SharedMatrixFactory . Attributes ) ; matrix1 . connect ( services1 ) ; const dataStoreRuntime2 = new MockFluidDataStoreRuntime ( ) ; const containerRuntime2 = containerRuntimeFactory . createContainerRuntime ( dataStoreRuntime2 ) ; const services2 = { deltaConnection : containerRuntime2 . createDeltaConnection ( ) , objectStorage : new MockStorage ( ) } ; matrix2 = new SharedMatrix ( dataStoreRuntime2 , "matrix2" , SharedMatrixFactory . Attributes ) ; matrix2 . connect ( services2 ) ; } ) ; it ( "create" , async ( ) => { matrix1 . insertRows ( 0 , Const . excelMaxRows ) ; matrix1 . insertCols ( 0 , Const . excelMaxCols ) ; containerRuntimeFactory . processAllMessages ( ) ; expectSize ( matrix2 , Const . excelMaxRows , Const . excelMaxCols ) ; } ) ; it ( "write corners" , async ( ) => { matrix1 . insertRows ( 0 , Const . excelMaxRows ) ; matrix1 . insertCols ( 0 , Const . excelMaxCols ) ; setCorners ( matrix1 ) ; checkCorners ( matrix1 ) ; containerRuntimeFactory . processAllMessages ( ) ; checkCorners ( matrix2 ) ; } ) ; it ( "remove corners (empty)" , async ( ) => { matrix1 . insertRows ( 0 , Const . excelMaxRows ) ; matrix1 . insertCols ( 0 , Const . excelMaxCols ) ; expectSize ( matrix1 , Const . excelMaxRows , Const . excelMaxCols ) ; containerRuntimeFactory . processAllMessages ( ) ; expectSize ( matrix2 , Const . excelMaxRows , Const . excelMaxCols ) ; matrix1 . removeRows ( matrix1 . rowCount - 1 , 1 ) ; matrix1 . removeRows ( 0 , 1 ) ; matrix1 . removeCols ( matrix1 . colCount - 1 , 1 ) ; matrix1 . removeCols ( 0 , 1 ) ; expectSize ( matrix1 , Const . excelMaxRows - 2 , Const . excelMaxCols - 2 ) ; containerRuntimeFactory . processAllMessages ( ) ; expectSize ( matrix2 , Const . excelMaxRows - 2 , Const . excelMaxCols - 2 ) ; } ) ; it ( "remove all (empty)" , async ( ) => { matrix1 . insertRows ( 0 , Const . excelMaxRows ) ; matrix1 . insertCols ( 0 , Const . excelMaxCols ) ; expectSize ( matrix1 , Const . excelMaxRows , Const . excelMaxCols ) ; containerRuntimeFactory . processAllMessages ( ) ; expectSize ( matrix2 , Const . excelMaxRows , Const . excelMaxCols ) ; matrix1 . removeRows ( 0 , matrix1 . rowCount ) ; matrix1 . removeCols ( 0 , matrix1 . colCount ) ; expectSize ( matrix1 , 0 , 0 ) ; containerRuntimeFactory . processAllMessages ( ) ; expectSize ( matrix2 , 0 , 0 ) ; } ) ; it ( "remove corners (populated)" , async ( ) => { matrix1 . insertRows ( 0 , Const . excelMaxRows ) ; matrix1 . insertCols ( 0 , Const . excelMaxCols ) ; setCorners ( matrix1 ) ; checkCorners ( matrix1 ) ; containerRuntimeFactory . processAllMessages ( ) ; checkCorners ( matrix2 ) ; matrix1 . removeRows ( matrix1 . rowCount - 1 , 1 ) ; matrix1 . removeRows ( 0 , 1 ) ; matrix1 . removeCols ( matrix1 . colCount - 1 , 1 ) ; matrix1 . removeCols ( 0 , 1 ) ; expectSize ( matrix1 , Const . excelMaxRows - 2 , Const . excelMaxCols - 2 ) ; containerRuntimeFactory . processAllMessages ( ) ; expectSize ( matrix2 , Const . excelMaxRows - 2 , Const . excelMaxCols - 2 ) ; } ) ; it ( "remove all (corners populated)" , async ( ) => { matrix1 . insertRows ( 0 , Const . excelMaxRows ) ; matrix1 . insertCols ( 0 , Const . excelMaxCols ) ; setCorners ( matrix1 ) ; checkCorners ( matrix1 ) ; containerRuntimeFactory . processAllMessages ( ) ; checkCorners ( matrix2 ) ; matrix1 . removeRows ( 0 , matrix1 . rowCount ) ; matrix1 . removeCols ( 0 , matrix1 . colCount ) ; expectSize ( matrix1 , 0 , 0 ) ; containerRuntimeFactory . processAllMessages ( ) ; expectSize ( matrix2 , 0 , 0 ) ; } ) ; } ) ; describe ( "local client summarize" , ( ) => { let matrix ; beforeEach ( async ( ) => { const dataStoreRuntime = new MockFluidDataStoreRuntime ( ) ; dataStoreRuntime . local = true ; matrix = new SharedMatrix ( dataStoreRuntime , "matrix1" , SharedMatrixFactory . Attributes ) ; } ) ; it ( "summarize" , async ( ) => { matrix . insertRows ( 0 , Const . excelMaxRows ) ; matrix . insertCols ( 0 , Const . excelMaxCols ) ; setCorners ( matrix ) ; checkCorners ( matrix ) ; const fromSummary = await summarize ( matrix ) ; checkCorners ( fromSummary ) ; } ) ; } ) ; } ) ;