18
18
*/
19
19
package org .apache .iotdb .db .storageengine .dataregion .memtable ;
20
20
21
+ import org .apache .iotdb .commons .concurrent .IoTDBThreadPoolFactory ;
21
22
import org .apache .iotdb .commons .exception .IllegalPathException ;
22
23
import org .apache .iotdb .commons .exception .MetadataException ;
23
24
import org .apache .iotdb .commons .path .AlignedFullPath ;
24
25
import org .apache .iotdb .commons .path .MeasurementPath ;
25
26
import org .apache .iotdb .commons .path .NonAlignedFullPath ;
26
27
import org .apache .iotdb .commons .path .PartialPath ;
28
+ import org .apache .iotdb .db .conf .IoTDBConfig ;
29
+ import org .apache .iotdb .db .conf .IoTDBDescriptor ;
27
30
import org .apache .iotdb .db .exception .WriteProcessException ;
28
31
import org .apache .iotdb .db .exception .query .QueryProcessException ;
32
+ import org .apache .iotdb .db .queryengine .common .FragmentInstanceId ;
33
+ import org .apache .iotdb .db .queryengine .common .PlanFragmentId ;
34
+ import org .apache .iotdb .db .queryengine .common .QueryId ;
35
+ import org .apache .iotdb .db .queryengine .exception .CpuNotEnoughException ;
29
36
import org .apache .iotdb .db .queryengine .exception .MemoryNotEnoughException ;
37
+ import org .apache .iotdb .db .queryengine .execution .driver .IDriver ;
38
+ import org .apache .iotdb .db .queryengine .execution .exchange .MPPDataExchangeManager ;
39
+ import org .apache .iotdb .db .queryengine .execution .exchange .sink .ISink ;
30
40
import org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceContext ;
41
+ import org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceExecution ;
42
+ import org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceStateMachine ;
31
43
import org .apache .iotdb .db .queryengine .execution .fragment .QueryContext ;
44
+ import org .apache .iotdb .db .queryengine .execution .schedule .IDriverScheduler ;
32
45
import org .apache .iotdb .db .queryengine .plan .planner .memory .MemoryReservationManager ;
33
46
import org .apache .iotdb .db .queryengine .plan .planner .plan .node .PlanNodeId ;
34
47
import org .apache .iotdb .db .queryengine .plan .planner .plan .node .write .InsertTabletNode ;
48
+ import org .apache .iotdb .db .storageengine .dataregion .DataRegion ;
35
49
import org .apache .iotdb .db .storageengine .dataregion .modification .ModEntry ;
36
50
import org .apache .iotdb .db .storageengine .dataregion .modification .TreeDeletionEntry ;
37
51
import org .apache .iotdb .db .storageengine .dataregion .wal .utils .WALByteBufferForTest ;
66
80
import java .util .List ;
67
81
import java .util .Map ;
68
82
import java .util .Random ;
83
+ import java .util .concurrent .ExecutorService ;
84
+
85
+ import static org .apache .iotdb .db .queryengine .execution .fragment .FragmentInstanceContext .createFragmentInstanceContext ;
69
86
70
87
public class PrimitiveMemTableTest {
88
+ private static final IoTDBConfig conf = IoTDBDescriptor .getInstance ().getConfig ();
89
+ private static final int dataNodeId = 0 ;
71
90
72
91
String database = "root.test" ;
73
92
String dataRegionId = "1" ;
@@ -100,6 +119,7 @@ public class PrimitiveMemTableTest {
100
119
@ Before
101
120
public void setUp () {
102
121
delta = Math .pow (0.1 , TSFileDescriptor .getInstance ().getConfig ().getFloatPrecision ());
122
+ conf .setDataNodeId (dataNodeId );
103
123
}
104
124
105
125
@ Test
@@ -194,6 +214,10 @@ public void simpleTest() throws IOException, QueryProcessException, MetadataExce
194
214
195
215
@ Test
196
216
public void totalSeriesNumberTest () throws IOException , QueryProcessException , MetadataException {
217
+ IoTDBConfig conf = IoTDBDescriptor .getInstance ().getConfig ();
218
+ int dataNodeId = 0 ;
219
+ conf .setDataNodeId (dataNodeId );
220
+
197
221
IMemTable memTable = new PrimitiveMemTable (database , dataRegionId );
198
222
int count = 10 ;
199
223
String deviceId = "d1" ;
@@ -588,7 +612,7 @@ public void testSerializeSize()
588
612
}
589
613
590
614
@ Test
591
- public void testReleaseWithNotEnoughMemory () {
615
+ public void testReleaseWithNotEnoughMemory () throws CpuNotEnoughException {
592
616
TSDataType dataType = TSDataType .INT32 ;
593
617
WritableMemChunk series =
594
618
new WritableMemChunk (new MeasurementSchema ("s1" , dataType , TSEncoding .PLAIN ));
@@ -599,16 +623,51 @@ public void testReleaseWithNotEnoughMemory() {
599
623
600
624
// mock MemoryNotEnoughException exception
601
625
TVList list = series .getWorkingTVList ();
626
+
627
+ // mock MemoryReservationManager
602
628
MemoryReservationManager memoryReservationManager =
603
629
Mockito .mock (MemoryReservationManager .class );
604
630
Mockito .doThrow (new MemoryNotEnoughException ("" ))
605
631
.when (memoryReservationManager )
606
632
.reserveMemoryCumulatively (list .calculateRamSize ());
607
633
608
- FragmentInstanceContext queryContext = Mockito .mock (FragmentInstanceContext .class );
609
- Mockito .when (queryContext .getMemoryReservationContext ()).thenReturn (memoryReservationManager );
610
- list .getQueryContextSet ().add (queryContext );
634
+ // create FragmentInstanceId
635
+ QueryId queryId = new QueryId ("stub_query" );
636
+ FragmentInstanceId instanceId =
637
+ new FragmentInstanceId (new PlanFragmentId (queryId , 0 ), "stub-instance" );
638
+ ExecutorService instanceNotificationExecutor =
639
+ IoTDBThreadPoolFactory .newFixedThreadPool (1 , "test-instance-notification" );
640
+ FragmentInstanceStateMachine stateMachine =
641
+ new FragmentInstanceStateMachine (instanceId , instanceNotificationExecutor );
642
+ FragmentInstanceContext queryContext =
643
+ createFragmentInstanceContext (instanceId , stateMachine , memoryReservationManager );
644
+ queryContext .initializeNumOfDrivers (1 );
645
+ DataRegion dataRegion = Mockito .mock (DataRegion .class );
646
+ queryContext .setDataRegion (dataRegion );
611
647
648
+ list .getQueryContextSet ().add (queryContext );
649
+ Map <TVList , Integer > tvlistMap = new HashMap <>();
650
+ tvlistMap .put (list , 100 );
651
+ queryContext .addTVListToSet (tvlistMap );
652
+
653
+ // fragment instance execution
654
+ IDriverScheduler scheduler = Mockito .mock (IDriverScheduler .class );
655
+ List <IDriver > drivers = Collections .emptyList ();
656
+ ISink sinkHandle = Mockito .mock (ISink .class );
657
+ MPPDataExchangeManager exchangeManager = Mockito .mock (MPPDataExchangeManager .class );
658
+ FragmentInstanceExecution execution =
659
+ FragmentInstanceExecution .createFragmentInstanceExecution (
660
+ scheduler ,
661
+ instanceId ,
662
+ queryContext ,
663
+ drivers ,
664
+ sinkHandle ,
665
+ stateMachine ,
666
+ -1 ,
667
+ false ,
668
+ exchangeManager );
669
+
670
+ queryContext .decrementNumOfUnClosedDriver ();
612
671
series .release ();
613
672
}
614
673
}
0 commit comments